我有一个显示数据的tableview。但我想定制细胞,我需要一些帮助。所以我有一个用于tableview的笔尖(HistoryViewController.xib)。我刚刚添加了类和nib来自定义tableview单元格(HistoryViewTableCell)。 我接下来要做的步骤是什么?我已经有了这个代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSDictionary * tempDictionary = [tableData objectAtIndex:indexPath.row];
cell.textLabel.text = [tempDictionary objectForKey:@"PickupAddress"];
return cell;
}
答案 0 :(得分:0)
答案 1 :(得分:0)
请尝试以下代码 -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
HistoryViewTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryViewTableCell"];
if (cell == nil) {
// Create a temporary UIViewController to instantiate the custom cell.
UIViewController *temporaryController = [[UIViewController alloc] initWithNibName:@"HistoryViewTableCell" bundle:nil];
// Grab a pointer to the custom cell.
cell = (HistoryViewTableCell *)temporaryController.view;
}
return cell;
}
或强>
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HistoryViewTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HistoryViewTableCell"];
if (cell == nil) {
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HistoryViewTableCell" owner:self options:nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}