在我使用下面的代码段中,细节文本标签不显示:detailtext标签没有显示出来
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"NEW";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath ];
if(cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
NSDictionary* item = [saleItems objectAtIndex:[indexPath row]];
cell.textLabel.text = [item valueForKey:@"name"];
cell.detailTextLabel.text = [item valueForKey:@"store"];
return cell;
}
然而
当我修改上述方法,以下面的详细文本出现了:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cellIdentifier = @"NEW";
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIdentifier];
UITableViewCell* cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
NSDictionary* item = [saleItems objectAtIndex:[indexPath row]];
cell.textLabel.text = [item valueForKey:@"name"];
cell.detailTextLabel.text = [item valueForKey:@"store"];
return cell;
}
第一种方法出了什么问题? 什么是使用dequeueReusableCellWithIdentifier的正确方法?