开发者

Using multiple custom cells without reusing identifier

I feel like a real noob asking this, but h开发者_如何学Cere's my problem:

I want to show a tableView, with 7 custom cells. None of these cells is reused. That means the user will see 7 different cells, not more, not less.

I created the cells in the viewDidLoad method, and added all those cells in the listCells-array. After that, I used easy-mode to draw those cells:

UITableViewCell *cell = nil;
if (indexPath.row == 0)
{
    static NSString *MyIdentifier = @"Cell";
    cell =  (DetAlertCell *)[localTableView dequeueReusableCellWithIdentifier:nil];

    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"DetAlertCell" owner:self options:nil];
        cell = [listCells objectAtIndex:indexPath.row];
    }
}
....

However, this won't work. It shows me a blank view. Every cell is created using a .xib-file and a .h and .m class. Is there anything that I'm missing and should do?


Just don't call the [localTableView dequeueReusableCellWithIdentifier:nil] and loa the correct cell for the index path.

Also you say that you load the cells in the viewDidLoad, then why do you load the nib:

 [[NSBundle mainBundle] loadNibNamed:@"DetAlertCell" owner:self options:nil];

They should already be the array should they not. And why to you check if the row is 0 then load the row, still will only load the first row.

Try this:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   return [listCells objectAtIndex:indexPath.row];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜