2017-06-19 112 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];