कई उपयोग की subviews के रूप में लेबल जोड़ने की तकनीक सेल, और शायद आप कोशिकाओं के पुन: उपयोग के साथ अप्रत्याशित परिणामों में भाग लेते हैं। ऐप्पल पहले से ही टेम्पलेट प्रदान करता है जिसे हर पहलू में अनुकूलित किया जा सकता है। आपके मामले में, कस्टम सेल का उपयोग किए बिना, और लेबल जोड़ने के बिना, मैं टेम्पलेट UITableViewCellStyleValue2
का उपयोग करता हूं, आप मौजूदा लेबल और एक्सेसरी व्यू के साथ खेल सकते हैं, जैसे cell.textLabel
, cell.detailTextLabel
और cell.accessoryView
, यह स्निपेट देखें जो आपके इंटरफ़ेस को कम या कम करता है:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.contentMode=UIViewContentModeScaleToFill;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
cell.textLabel.textAlignment=UITextAlignmentCenter;
cell.textLabel.font=[UIFont boldSystemFontOfSize:22];
cell.textLabel.textColor=[UIColor lightGrayColor];
cell.detailTextLabel.contentMode=UIViewContentModeScaleToFill;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.baselineAdjustment=UIBaselineAdjustmentAlignCenters;
cell.detailTextLabel.textAlignment=UITextAlignmentLeft;
cell.detailTextLabel.font=[UIFont boldSystemFontOfSize:23];
cell.detailTextLabel.textColor=[UIColor blackColor];
[email protected]"Tel.:";
[email protected]"+3912345678";
UIImageView *imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"phone.png"]];
cell.accessoryView = imageView;
[imageView release];
return cell;
}
उम्मीद है कि इससे मदद मिलती है।
आप हमेशा UITableViewCell और दो UILabels को उपclass कर सकते हैं। – tilo