我是 Objective-C 和 iOS 的初学者,我尝试学习如何为 iOS 开发出色的应用程序。
我尝试创建一个 TableViewController,所以我创建了一个类,但是这段代码有一些问题,我不知道为什么。我在评论中的代码中描述了所有内容。
这是代码。
BooksTableViewController.m
import "BooksTableViewController.h"
@implementation BooksTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil //Semantic Issue - Designated initializer missing a 'super' call to a designated initializer of the super class
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];// Parse Issue - Expected expression
if(self){
self.title = @"Books";
self.tabBarItem.image = [UIImage imageNamed:@"books8.png"];
self.imiona = @[@"Pan Tadeusz", @"Potop", @"Lalka", @"Uczta dla wron", @"Symfonnia C++"];
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.imiona.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Title"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Title"];
}
cell.textLabel.text = self.imiona[indexPath.row];
return cell;
}
@end
谢谢你的帮助!
最佳答案
在initWithNibName
在 nimNameOrNil
有问题。您所要做的就是:更改此行
self = [super initWithNibName:<#nibNameOrNil#> bundle:nibBundleOrNil];
到
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];
通知:<#nibNameOrNil#>
与 nibNameOrNil
关于ios - Objective-C - TableView Controller - 预期的表达,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30055281/