2013-07-16 51 views
0

在我目前的应用程序中,我有24个不同的视图,每个视图都有它自己的ViewController。随着时间的流逝,我已经认识到,将它们改为TableViewController不仅会更好地发挥作用,而且事实上它会更好看。如何将自定义类添加到我的UITableViewController?

通常情况下,我一直在为我的视图分配自定义类的方式是在Xcode中进入:File> New> File> Objective-C Class。

我做了这个类,并确保它是UIViewController的一个子类。文件创建完成后,我单击故事板文件中的View Controller,转到检查器并将自定义类设置为myNewViewController,全部完成!

但是,在使用UITableView时,情况并非如此,我可以在故事板文件中添加表格视图,自定义/添加节/单元格等,但是当我想要分配新类时我创建遵守上述步骤,但这次我从UITableViewController

我得到以下警告子类: enter image description here

有了这个是不完整的代码:

- (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链接起来?这种方式都不需要这种配置?

我的下一步要遵循什么?

感谢您的&意见!

编辑我也试图设置小区标识为“细胞”,并试图改变值,以便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' 
*** 

回答

1

您正在使用静态单元。您不应该使用数据源方法。

+0

我编辑了问题中的代码,您提到的方法已经实现。 @Abdullah Shafique – vzm

+0

是的,但在这种方法中,你应该确定这些单元包含的内容。 –

+0

您是否在故事板中设置了单元格标识符? –

相关问题