यह मेरा cellForRowAtIndexPath UITableView प्रतिनिधि विधि के लिए संक्षिप्त कोड है:UITableView indexPath खंड तर्क
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"blahblahblah"];
if (cell == nil) {
// No cell to reuse => create a new one
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"blahblahblah"] autorelease];
}
cell.textLabel.text = @"";
cell.detailTextLabel.text = @"";
cell.backgroundView = NULL; //problem here
// Initialize cell
//blah blah blah
//now to the good part...
if(indexPath.section == 1) {
cell.backgroundView = deleteButton;
cell.userInteractionEnabled = YES;
cell.textLabel.text = nil;
cell.detailTextLabel.text = nil;
}
else if(indexPath.section == 0) {
NSLog(@"section: %i row: %i", indexPath.section, indexPath.row);
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"foobar";
//more stuff
break;
//lots more cases
default:
break;
}
}
return cell;
}
मेरे समस्या यह है कि में खंड 1 (अनुभाग 0 प्रथम कक्ष 10 कोशिकाओं, खंड 1 है केवल 1 सेल है) जानकारी को असाइन किया जा रहा है जिसे केवल पहले खंड के सेल 0 को असाइन किया जाना चाहिए। तो, हटाएं बटन पृष्ठभूमि और आदि प्राप्त करने के बजाय, इसे लेबल शीर्षक "foobar" मिलता है। मुझे सच में यकीन नहीं है कि यह क्यों हो रहा है, क्योंकि मेरे अगर कथन बहुत स्पष्ट हैं। कोई विचार?
संपादित करें: पृष्ठभूमि को सेट करने से NULL को देखने के लिए उन कक्षों को टेक्स्ट के साथ, जब वे दृश्य छोड़ते हैं, किसी भी पृष्ठभूमि के बिना वापस आते हैं। तो यह एक व्यवहार्य समाधान नहीं है। साथ ही, विवरण टेक्स्ट टेक्स्ट के लिए पाठ अभी भी उस सेल पर सेट है जिसमें कोई टेक्स्ट नहीं होना चाहिए। के रूप में एलेक्स समझना (द्वारा सिफारिश की
समाधान,:
यह है कि यह कैसे सेल backgroundViews शून्य करने के लिए सेट और नष्ट सेल पर प्रदर्शित पाठ के साथ, लग रहा है वह जगह है जहाँ ऐसा नहीं होना चाहिए इस कोड के साथ) वर्ष विपंक्ति कोड की जगह:
NSString* identifier;
if(indexPath.section == 0)
identifier = @"0";
else
identifier = @"1";
UISwitch *switchView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
// No cell to reuse => create a new one
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier] autorelease];
आह, हाँ, उसने ऐसा किया। समाधान के साथ सवाल अद्यतन किया। –