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/

相关文章:

objective-c - 如何更新 UITableView 中的数据?

ios - 我应该为高级帐户创建消耗品订阅还是不可续订订阅?

ios - 如何绘制NSString atPoint withAttributes 并调整SIZE?

ios - sliderValueDidChange 被多次调用

iphone - 是否可以跨 2 个不同的 iOS 应用程序访问数据?

ios - 在 ScrollView 中垂直滚动时 ImageView 移到一边

arrays - 错误 : Cannot set UITableViewCell labels and images with custom cell class! 只能加载单元格样式的数据:字幕不是自定义的

ios - 具有单选和多选的uitableview

swift - 如何在 Swift IOS 中隐藏 UIProgressView

ios - UITextField 中 Caret/Cursor 的奇怪行为