[英]How to add a custom class to my UITableViewController?
在我当前的应用程序中,我有24个不同的视图,每个视图都有自己的ViewController
。 随着时间的流逝,我逐渐意识到将它们更改为TableViewController
不仅功能更好,而且实际上看起来也更好。
通常,将自定义类分配给视图的方式是在Xcode中执行以下操作:File> New> File> Objective-C Class。
我创建该类,并确保它是UIViewController
的子类。 创建文件后,我在Storyboard文件中单击我的View Controller,转到检查器并将自定义类设置为myNewViewController
,全部完成!
但这不是使用UITableView
时的情况,我能够在情节提要文件中添加表格视图,对其进行自定义/添加节/单元格等,但是当我想分配自己创建的新类时按照上述步骤操作,除了这次我从UITableViewController
子类
我收到以下警告:
这是不完整的代码:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
return cell;
}
此外,在我的iOS设备上运行时,该视图显示为空白。
我知道该实现必须正确完成才能正常运行,但是有没有一种特定的方法可以链接我正在使用的视图及其ViewController? 这样不需要配置吗?
我下一步要做什么?
谢谢你的建议!
编辑我还尝试将单元格标识符设置为“ Cell”,还尝试更改值,以使numberOfSections返回5,numberOfRowsInSection返回2,但仍然没有运气,应用程序崩溃了,我在调试日志中得到了此信息:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
***
您正在使用静态单元格。 您不应该使用数据源方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.