我無法讓我的CustomTableViewCell
,UITableViewCell
的子類出現在我的表格視圖中。使用XIB文件加載UITableViewCell子類
我使用xib來表示該單元格,但我假設數據源委託的代碼不會更改。我確保在表格視圖單元格XIB中設置一個相同的重用標識符。
我找出問題的事實,即返回表格單元格的數據源的方法不能正常工作,那就是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
DataObject *foo = [self.dataArray objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell overview] setText:foo.overview];
[[cell price] setText:foo.price];
NSLog(@"cell initialized, description text is %@",cell.overview.text);
return cell;
}
不知道爲什麼,這是行不通的,但最後的日誌語句總是在最後打印一個(null),而且我確實證實數據對象的overview
屬性在其中有一個有效的字符串。 price
同樣的事情。
http://stackoverflow.com/questions/4195726/how-to -create-custom-tableviewcell-from-xib試試!!!我認爲你的答案在那裏! – trumpetlicks
是的,它可以工作,但是當我在前幾次嘗試該方法時遇到了異常,請參閱我對如何避免接受的答案的評論。 –
嘿@AndrewLauerBarinov,所以我在同一個問題atm,但我用故事板代替。想知道您對接受答案的評論,我似乎並不明白「IBOutlet與您所說的視圖不是文件所有者」的關係。對不起,我有點新與ios,所以我仍然試圖學習我需要做的連接和東西方面的東西。你能請進一步解釋一下嗎?謝謝!還在這裏發佈的東西http://stackoverflow.com/questions/15175472/custom-uitableviewcell-will-not-display-label-texts – gdubs