मैं इस मामले के लिए एक फ़ंक्शन बनाता हूं और यह मेरे लिए अच्छा काम करता है .. इसे आजमाएं, सेल निर्माण में पहले आप उस पंक्ति को देख सकते हैं जिसमें आप UISwitch
को पूर्व में जोड़ना चाहते हैं।
if(indexPath.row == 0)
[self createOnOffView:cell withTitle:@"Somthing" withTag:1001 defaultVal:YES];
और समारोह है:
- (void) createOnOffView:(UITableViewCell*) cell withTitle:(NSString*) title withTag:(int)tag defaultVal:(BOOL) defaultVal
{
CGRect rect;
cell.textLabel.text = title;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
rect = cell.contentView.frame;
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
rect.origin.x = cell.frame.size.width - 20;
else
rect.origin.x = rect.size.width/2 +35;
rect.origin.y = rect.size.height/2 - 15;
rect.size.width = 60;
UISwitch *switchView = [[UISwitch alloc] initWithFrame:rect];
[cell.contentView addSubview:switchView];
[switchView addTarget:self action:@selector(didChangeSwitch:) forControlEvents:UIControlEventValueChanged];
switchView.tag = tag;
[switchView setOn:defaultVal];
[switchView release];
}
और जब मूल्य है स्विच को इस विधि के सक्रिय होने का है .. ताकि आप जान सकें जो टैग के आधार पर स्विच
- (void) didChangeSwitch:(UISwitch*)switchView
{
if(switchView.tag == 1001)
{
//Do Somthing
}
if(switchView.tag == 1002)
{
//Do Somthing
}
}
आशा है कि यह सहायक होगा :)
स्रोत
2012-05-29 12:32:43
+1 स्थैतिक टीवी इसे पाई के रूप में आसान बनाता है। :) – lnafziger
नोट करें कि स्टोरीबोर्डिंग के दौरान स्थिर UITableViewCell पर एक UISwitch तत्व खींचने के लिए, सेल शैली "कस्टम" – Archie1986
@ Archie1986 की शैली होनी चाहिए, यह "मूल" कोशिकाओं के लिए भी काम करता है, हालांकि कुछ मजबूती के साथ। –