gpt4 book ai didi

iphone - UITableView 自定义单元格抛出 SIGABRT 错误

转载 作者:太空狗 更新时间:2023-10-30 03:46:19 24 4
gpt4 key购买 nike

我正在尝试为我的 UITableView 创建自定义单元格。我正在使用 Xcode 4.2 并将 Storyboard与 ARC 一起使用。

我创建了一个类来表示自定义单元格,如下所示:

ResultsCustomCell.h

#import <UIKit/UIKit.h>

@interface ResultsCustomCell : UITableViewCell
{
IBOutlet UILabel *customLabel;
}

@property (nonatomic, retain) IBOutlet UILabel* customLabel;

@end

ResultsCustomCell.m

#import "ResultsCustomCell.h"

@implementation ResultsCustomCell

@synthesize customLabel;

@end

然后我在我的 View Controller 中实现了 UITableView 方法,如下所示:ViewController.m

#import "ViewController.h"
#import "ResultsCustomCell.h"

@implementation ViewController

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
}

// Set the number of items in the tableview to match the array count
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}

// Populate TableView cells with contents of array.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";

ResultsCustomCell *myCell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
myCell.customLabel.text = @"helloWorld";

return myCell;
}

// Define height for cell.
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80;
}

@end

应用程序构建成功,但立即崩溃并给我以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

我错过了什么?

最佳答案

这是一个恼人的问题,因为调试器不会让您知道发生了什么。如果您单击“继续执行”,它会在出现异常时中断,然后简单地关闭。

这让我抓狂了 30 分钟,直到我右键单击自定义单元格中出现问题的 UILabel,这揭示了答案:单元格中的一个控件已经(或者已经,正如你显然修复的那样,也许没有注意到)一个虚假的导出。 “虚假 socket ”是指连接到您的类(class)中不再存在的 IBOutlet 属性的 socket 。在我的例子中,我更改了属性的名称并重新布线,但忘记删除旧的引用 socket 连接。

一旦我移除了有问题的 socket ,问题就消失了。

关于iphone - UITableView 自定义单元格抛出 SIGABRT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9364523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com