我不知道为什么我的应用程序崩溃。这是代码:
-(void)viewDidLoad
{
[super viewDidLoad];
self.tableContent = [NSArray arrayWithObjects:@"Blue", @"Yellow", @"Green", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableContent count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
return [self.tableContent objectAtIndex:indexPath.row];
}
这是我得到的错误
-[NSCFString setTableViewStyle:]: unrecognized selector sent to instance 0x4938
最佳答案
这是您的cellForRowAtIndexPath
中的错误:
return [self.tableContent objectAtIndex:indexPath.row];
tableContent
是NSString
的数组,因此您将返回NSString
而不是UITableViewCell
类型的对象。所以写:return cell;
导致错误的原因是您返回的
NSString
代替了UITableViewCell
...如果要查看发送的文本,则需要设置textlabel的文本:cell.textlabel.text = [self.tableContent objectAtIndex:indexPath.row];
//set the text and then return the cell
return cell;
关于objective-c - 应用在initWithStyle上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9530122/