2017-06-19 109 views
-1

我的UITableCell標題在我的viewController未顯示。TableViewCell標題不顯示

它有什麼問題?

我已經拖動了TableViewTableViewCell但它沒有顯示,它保持白色。

截圖:https://blazor.nl/uploads/get/19d2ed8a2662039e1104474b0426f2e0/IMG-0286

我用下面的代碼

-(void) arraySetup{ 
    imageNameArray = [NSMutableArray arrayWithArray:@[@"image1", @"image2", @"image3", @"image4"]]; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return imageNameArray.count; 
} 

#pragma mark - UITableView DataSource Methods 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellId = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 

    return cell; 
} 

請諮詢我該怎麼辦呢?

+0

你連接的委託和數據源? – DonMag

+0

是的,我做到了。 tabel和它的單元格就在第二個視圖控制器中。 – Anoniem

+0

請問您可以發佈您的代碼,以便快速查找相關內容 –

回答

2

這是顯而易見的,因爲你出列一個表格視圖單元格(這就是,基本上模板),但你不加油吧數據。所以:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellId = @"cell"; 

    // Fix: Use dequeueReusableCellWithIdentifier:forIndexPath: instead 
    // of dequeueReusableCellWithIdentifier: alone. The new method 
    // ensures you won't get a nil cell and, thus, crashing your app. 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId 
                  forIndexPath:indexPath]; 

    // Grab your data here 
    NSString *theTitle = imageNameArray[indexPath.row]; 

    // And set the title of your cell 
    cell.textLabel.text = theTitle; 

    return cell; 
} 
-1

你可以在你的tableview使用titleForHeaderInSection:

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
    return "Your tittle here" } 
+0

對不起,這是客觀的C.忘了說。 – Anoniem

+0

標題標題與單元格標題不同。 – Koen

0

你沒有使用過的任何地方你imageNameArray中的tableView的cellForRowAt這就是爲什麼沒有顯示你的數據。您正確出列tableView,但沒有提供任何數據顯示。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellId = @"cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId]; 
    CellLabel = (UILabel*) [ cell.contentView viewWithTag:2];  
    CellLabel = [imageNameArray objectAtIndex:indexPath.row]; 
    return cell; 
} 

如果您使用的是默認的tableView 那麼你可以插入

cell.textLabel.text = [imageNameArray objectAtIndex:indexPath.row];