ios - 使用简单的 Storyboard应用程序获取 SIGABRT 错误

标签 ios uitableview sigabrt uncaught-exception

我有一个问题,我在互联网上搜索了解决方案,但无济于事。我正在关注 Storyboard上 Apress 的 Beginning iOS 5 development 的第 10 章。

我认为这本书缺少一段简单的代码,因为我是第一次阅读它,所以我不知道如何解决它。

我已经重新启动了项目两次,但在调试器中一直出现此错误:

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath: 返回一个单元格:”

#import "BIDTaskListController.h"

@interface BIDTaskListController ()
@property (strong, nonatomic) NSArray *tasks;
@end

@implementation BIDTaskListController

@synthesize tasks;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tasks = [NSArray arrayWithObjects:
                  @"Walk the dog",
                  @"URGENT:Buy milk",
                  @"Clean hidden lair",
                  @"Invent miniature dolphins",
                  @"Find new henchmen",
                  @"Get revenge on do-gooder heroes",
                  @"URGENT: Fold laundry",
                  @"Hold entire world hostage",
                  @"Manicure",
                  nil];
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

    self.tasks = nil;
}

//

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [tasks count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *identifier = nil;
    NSString *task = [self.tasks objectAtIndex:indexPath.row];
    NSRange urgentRange = [task rangeOfString:@"URGENT"];
    if (urgentRange.location == NSNotFound) {
        identifier = @"plainCell";
    } else {
        identifier = @"attentionCell";
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
    cellLabel.text = task;

    return cell;
}
@end

最佳答案

缺少代码:

...

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    UILabel *label = [[UILabel alloc] initWithFrame:cell.bounds];
    label.tag = 1;
    [cell addSubview:label];
}

UILabel *cellLabel = (UILabel *)[cell viewWithTag:1];
cellLabel.text = task;   

....

关于ios - 使用简单的 Storyboard应用程序获取 SIGABRT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10269764/

相关文章:

iphone - 添加自定义操作:@selector to UISwitch on TableViewCell

ios - 适用于 iOS 的 Paypal SDK

ios - 使用UITable显示数据但显示错误

iphone - 当从 UIViewController 文件移动到单独的类文件时,UIActionSheet 代码崩溃

iphone - 如何对图像进行圆角处理

ios - 如何在 uitableviewcontroller 中动态添加单元格?

iphone - UITableview 中的水平和垂直滚动

ios - 从 plist 中检索数据

ios - 用指针转换 CFDictionaryRef?

swift - Tableview的Sigabrt错误