在我的UITableView
,我想在最後一個單元格中顯示加載指示器。 對於剩餘的單元格,我創建了一個工作正常的自定義表格視圖單元格。但是,當我滾動到結尾,它的崩潰,無法加載加載指示器(這是一個不同的自定義單元格視圖)。這是我的代碼。iPhone - UITableView顯示兩個不同的自定義單元格視圖
- (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;
}