चलो कहते हैं कि मेरे पास है कि चलोकस्टम कोशिकाओं के लिए dequeueReusableCellWithIdentifier का उपयोग
- (UITableViewCell*)tableView:(UITableView*) cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
static NSString *cellID = @"Cell Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
else
{
return cell;
}
UILabel * nameLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 15, box.size.width, 19.0f)];
nameLabel.text = name;
[nameLabel setTextColor: [UIColor colorWithRed: 79.0f/255.0f green:79.0f/255.0f blue:79.0f/255.0f alpha:1.0f]];
[nameLabel setFont: [UIFont fontWithName: @"HelveticaNeue-Bold" size: 18.0f]];
[nameLabel setBackgroundColor: [UIColor clearColor]];
nameLabel.textAlignment = NSTextAlignmentCenter;
[cell addSubview: nameLabel];
}
क्या है कि क्या करने जा रहा है?
यदि सेल शून्य नहीं है, और मान लें कि आप पंक्ति 5 पर हैं, तो क्या यह पंक्ति 5 के लिए सटीक पाठ लेबल आदि के साथ सेल वापस कर देगा?
असल में, मेरा प्रश्न यह है कि यदि आपके पास लेबल, छविदृश्य आदि के साथ कस्टम कक्ष हैं, तो आप cellForRowAtIndexPath
dequeueReusableCellWithIdentifier
के साथ कैसे उपयोग करते हैं?
यह tableviewcell के लिए समान है चाहे वह कस्टम है या नहीं। आप सेल ऑब्जेक्ट को पकड़ते हैं और अपने सभी राज्यों को रीसेट करते हैं और फिर अपनी सामग्री जोड़ते हैं। तो हाँ, आपको लेबल/छवियों में सामग्री को साफ करना होगा (इसे शून्य पर सेट करके) और नई सामग्री प्रदान करें। – rydgaze
इस कोड में, सेल के सबव्यूज़ को समझाकर UILabel ऑब्जेक्ट को फिर से एक्सेस करने का कोई तरीका नहीं है जो बहुत बदसूरत है। UITableViewCell के उप-वर्ग का उपयोग करने के लिए बेहतर है जिसमें UILabel प्रॉपर्टी है, इसलिए यह आसानी से सुलभ हो सकता है –