它做到這一點很簡單:
在customcell首先創建標籤的屬性
Customcell.h
@interface CustomCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UILabel *yourLabel;
現在創建customcell實例您的TableViewController
YourTableViewController.h
@interface YourTableViewController : UITableViewController<
{
CustomCell *cell;
}
和YourTableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
cell.yourLabel.text = @"whatever you want to add";
現在
,如果你想在其他的方法來更新customcell的標籤不僅僅是做到這一點。
-(void)someMethod()
{
CustomCell *acell = (CustomCell *)[tableView cellForRowAtIndexPath:n];
acell.yourLabel.text = @"whatever you want to add.";
}