ios - 更改 TableViewController.swift 类

标签 ios swift uitableview

我有一个 TableViewController,其中有一些单元格。这些单元格具有不同的背景颜色和文本。在测试应用程序时,它们没有问题,但我需要向 TableViewController 添加一个类,因此我转到“自定义类”选项卡并输入该类,之后,我的 TableViewController 只是加载空。这是为什么?

只有当我改变类(class)时才会发生这种情况。

最佳答案

在您的自定义类中,您需要实现如下数据源:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

return self.yourArray.count;}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

 static NSString *CellIdentifier = @"Cell";
customCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textlabel.text = @"hi";

return cell;}

关于ios - 更改 TableViewController.swift 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33460215/

相关文章:

ios - 从 UIWebView 打印 PDF 会产生未缩放的页面

c++ - 未找到 Xcode 的 cmath

ios - Swift中SKShapeNode的浮点问题

ios - 在字符串 Swift 之间拆分 HTML 字符串

ios - tableview中可见单元格的方法

ios - iOS触发单个单元格tableView:heightForRowAtIndexPath:

ios - indexPathForRowAtPoint.row 始终为 tableView 中的每个单元格返回零

ios - UIActionsheet 背景清晰颜色

ios - 如何在 instagram 中分享图片?Swift

ios - 我的 textView bottomAnchor 似乎不起作用?