【发布时间】:2015-05-05 14:05:58
【问题描述】:
我是 Objective-C 和 iOS 方面的初学者,我尝试学习如何为 iOS 开发出色的应用程序。
我尝试创建一个 TableViewController,所以我创建了一个类,但是这段代码有一些问题,我不知道为什么。我在 cmets 的代码中描述了所有内容。
这是代码。
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
感谢您的帮助!
【问题讨论】:
-
将此行
self = [super initWithNibName:<#nibNameOrNil#> bundle:nibBundleOrNil];更改为self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil]; -
Alos 尝试在 'viewDidLoad' 函数上编写此代码
self.title = @"Books"; self.tabBarItem.image = [UIImage imageNamed:@"books8.png"]; self.imiona = @[@"Pan Tadeusz", @"Potop", @"Lalka", @"Uczta dla wron", @"Symfonnia C++"]; -
错误消失了,但现在这里有一个“线程 1:断点 1.1”,应用程序无法运行。有什么问题?
-
你添加了断点吗?请删除断点并再次运行。如果我错了,请分享错误的屏幕截图
-
我打开了两个 symulator,所以这就是brakeponint 的问题。非常感谢您的帮助:)
标签: ios objective-c