我已經閱讀了許多關於類似問題的文章,但似乎沒有任何工作,我顯然做錯了什麼。我有一個在StoryBoard(XCode 5)中的TableViewController。對於PrototypeCell,我將類型設置爲自定義,並將標識符設置爲「pbvcell」。我加了一些標籤,改變背景等。下面是設置單元格的原型Cell沒有被tableview使用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pbvcell"];
// Configure the cell...
PBVlead *lead = [self.leads objectAtIndex:indexPath.row];
NSLog(@"Cell class %@", [cell class]);
UILabel *leadNameLabel = (UILabel *)[cell viewWithTag:1];
leadNameLabel.text = lead.leadName;
return cell;
}
我的tableview委託方法現在應用程序啓動,但即使我添加對象的實現代碼如下數據源陣列,並做了重裝數據,單元格是空白的,就像沒有使用自定義單元格一樣。看起來這應該很容易,而這就是我需要做的。我究竟在想什麼?
我還沒有使用Storyboa rds,但通常您需要檢查從[[tableView dequeueReusableCellWithIdentifier:]'返回的對象是否爲'nil',如果是,則使用'[[subclass alloc] initWithStyle:reuseIdentifier:]''實例化一個新單元格。 – Graham
@Graham,如果單元格是在故事板中定義的,則不需要這樣做。 – rdelmar
@Graham:如果單元格被註冊爲故事板中的原型單元格,則不需要。如有必要,單元格將自動實例化。 –