gpt4 book ai didi

iphone - 从 Nib 加载 UITableView

转载 作者:行者123 更新时间:2023-12-03 16:18:01 27 4
gpt4 key购买 nike

加载 UITableView 时我不断崩溃。我正在尝试使用在 nib 文件中定义的单元格。

我在 View Controller 头文件中定义了一个 IBOutlet:

UITableViewCell *jobCell;
@property (nonatomic, assign) IBOutlet UITableViewCell *jobCell;

这是在实现文件中综合的。

我在 IB 中创建了一个 UITableViewCell,并将其标识符设置为 JobCell。

这是 cellForRowAtIndexPath 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"JobCell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"JobsRootViewController" owner:self options:nil];
cell = jobCell;
self.jobCell = nil;
}

// Get this job
Job *job = [fetchedResultsController objectAtIndexPath:indexPath];

// Job title
UILabel *jobTitle;
jobTitle = (UILabel *)[cell viewWithTag:tagJobTitle];
jobTitle.text = job.title;

// Job due date
UILabel *dueDate;
dueDate = (UILabel *)[cell viewWithTag:tagJobDueDate];
dueDate.text = [self.dateFormatter stringFromDate:job.dueDate];

// Notes icon
UIImageView *notesImageView;
notesImageView = (UIImageView *)[cell viewWithTag:tagNotesImageView];
if ([job.notes length] > 0) {
// This job has a note attached to it - show the notes icon
notesImageView.hidden = NO;
}
else {
// Hide the notes icon
notesImageView.hidden = YES;
}

// Job completed button

// Return the cell
return cell;

}

当我运行应用程序时 - 我遇到了严重崩溃,控制台报告以下内容:

objc[1291]: FREED(id): message style sent to freed object=0x4046400



我已经正确连接了 IB 中的所有网点。问题是什么?

谢谢,

最佳答案

最简单的方法是将其分成两个单独的 nib 文件,然后从单元格自己的 nib 加载单元格。需要注意的是,你不能像这样设置 socket ,如果你想这样做,你需要一个自定义 UITableViewCell 子类。但是如果你没有在单元中连接任何东西,你可以简单地这样做:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"JobsRootViewCell" owner:nil options:nil] objectAtIndex:0];
}

关于iphone - 从 Nib 加载 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2562358/

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