2012-12-25 19 views
0

非常奇怪的問題。我有一個自定義單元格的故事板UITableViewController。出於某種原因,單元格不顯示在我的TableView中。我把一些斷點和一些日誌消息,我可以告訴它獲取數據,我可以看到單元格有一個內存地址,所以它不是零。我只是不知道還有什麼要驗證的。UITableViewCell被分配但不顯示

由於某些原因,單元格的隱藏屬性被設置爲YES,所以我添加了cell.hidden = NO,但它仍然沒有出現。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSString *CellIdentifier; 
if(indexPath.section == 0) { 
    CellIdentifier = @"HeaderCell"; 
} else { 
    CellIdentifier = @"ConnectedGoalCell"; 
} 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

if(indexPath.section == 0) { 
//Section 0 Formatting.....displays OK 
} else { 
//This is the cell that doesn't appear in the tableView 

    UILabel * nameLabel = (UILabel*)[cell viewWithTag:10]; 
    UILabel * dateLabel = (UILabel*)[cell viewWithTag:11]; 

    NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; 
    formatter.timeZone = [NSTimeZone defaultTimeZone]; 
    [formatter setDateFormat:@"MM/dd/yyyy"]; 
    Goal * goal = [connectedGoals objectAtIndex:indexPath.row]; 
    nameLabel.text = goal.name; 
    dateLabel.text = [formatter stringFromDate:goal.goal_date]; 
    //Log said that cell HIDDEN was YES. Changed to no here but still no effect 
    //<UITableViewCell: 0xa288e30; frame = (0 389; 320 44); autoresize = W; layer = <CALayer: 0xa292a80> 
    cell.hidden = NO; 
    NSLog(@"CELL TYPE : %@ AT %@", indexPath, CellIdentifier); 
    //Logs:: CELL TYPE : <NSIndexPath 0xc3917d0> 2 indexes [1, 0] AT ConnectedGoalCell 

    NSLog(@"%@", cell); 
    //Logs:: CELL TYPE : <UITableViewCell: 0xc195ba0; frame = (0 389; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0xc171620> 

} 

return cell; 
} 
+0

檢查您的'ConnectedGoalCell'的隱藏屬性。它正在隱藏。 – Ilanchezhian

+0

更新了我的問題,謝謝。雖然顯然相關,似乎並沒有解決我的問題。 – ChickensDontClap

回答

0

閱讀你的日誌

細胞類型:的UITableViewCell:0xc195ba0; frame =(0 389; 320 44); hidden = YES; autoresize = W;

我不知道它爲什麼隱藏,但顯然不應該。

cell.hidden = NO; 
+0

感謝您的支持。我不知道它將如何設置爲隱藏我沒有在故事板中這樣做。它仍然沒有效果。單元格不顯示,但確實顯示單元格所需的空間是。會不會有其他一些會使細胞不可見的特性? – ChickensDontClap

0

您正在使用dequeueReusableCellWithIdentifier:forIndexPath:方法(而不是在dequeueReusableCellWithIdentifier:方法,然後nil檢查),這意味着你必須調用,發言權register*:forCellReuseIdentifier之一,viewDidLoad。從文檔:

要點:必須調用此方法 之前註冊使用 registerNib:forCellReuseIdentifier:registerClass:forCellReuseIdentifier:方法的類或筆尖文件。

+0

不在我的機器前面,但對這一步感到好奇是必要的,因爲我在故事板中定義了單元格 – ChickensDontClap

1

最終必須在我的故事板中創建一個新的TableViewController並重新設置我的自定義視圖,現在一切正常現在我的一個自定義單元有大約20個按鈕,幸運的是我能夠粘貼它們而不是繁瑣地重新創建它們。非常奇怪的錯誤,但現在它的工作!