iPhone-UITableView显示两个不同的自定义单元格视图 [英] iPhone - UITableView to show two different custom cell views
本文介绍了iPhone-UITableView显示两个不同的自定义单元格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的 UITableView
中,我想在最后一个单元格中显示加载指示器.对于其余单元格,我创建了一个自定义表格视图单元格,该单元格运行良好.但是,当我滚动到末尾时,它崩溃并且无法加载加载指示符(这是一个不同的自定义单元格视图).这是我的代码.
In my UITableView
, I want to show loading indicator in the last cell.
For remaining cells, I created a custom table view cell which is working fine. But when I scroll to the end, its crashing and not able to load loading indictor (which is a different custom cell view). Here's my code.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HomeViewCell";
UITableViewCell* cellToReturn = nil;
// Configure the cell.
NSInteger row = [indexPath row];
if (row < [jokesTableArray count])
{
CustomTableCell* cell = (CustomTableCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[CustomTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary* dict = [jokesTableArray objectAtIndex:indexPath.row];
NSNumber* rating = [[ServerCommunicator getInstance] getCurrentUserJokeRating:[dict objectForKey:@"id"]];
cell.userRatedTheJoke = rating != nil ? YES : NO;
cell.titleLabel.text = [dict objectForKey:@"title"];
cell.descriptionLabel.text = [dict objectForKey:@"text"];
cell.upVotes.text = [NSString stringWithFormat:@"%2.2f",[[dict objectForKey:@"rating_count"] floatValue]];
[cell setRating:rating != nil ? [rating intValue] : [[dict objectForKey:@"rating_count"] intValue]];
NSString* authorName = [dict objectForKey:@"author"];
if (authorName != nil && ![authorName isEqual:[NSNull null]])
{
cell.author.text = [NSString stringWithFormat:@"By:%@",authorName];
}
cellToReturn = cell;
}
else
{
KMLoadingIndicatorCell* cell = (KMLoadingIndicatorCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
KMLoadingIndicatorCell* cell = [[[KMLoadingIndicatorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.loadingLabel.text = @"Loading...";
cellToReturn = cell;
}
}
return cellToReturn;
}
推荐答案
您应为自定义单元格使用其他单元格标识符.
You should use a different Cell Identifier for your custom cell.
这篇关于iPhone-UITableView显示两个不同的自定义单元格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文