gpt4 book ai didi

ios - Signal SIGABRT 简单 TableView

转载 作者:行者123 更新时间:2023-11-29 11:03:18 25 4
gpt4 key购买 nike

我只是按照教程中的几个步骤创建了一个包含 50 行的简单 TableView,但我得到了“Signal SIGABRT”:/我将 Storyboard 中的 TableView 与我创建的 TableViewController 类连接起来。

这是我的简单代码:

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

// Configure the cell...

cell.textLabel.text = [NSString stringWithFormat:@"Row %i",indexPath.row];

return cell;
}

最佳答案

欢迎来到 Stack Overflow!不久前,设置 UITableViewCell 的标准方法略有变化。这意味着 Xcode 为 tableViews 提供的模板代码使用 -tableView: dequeueReusableCellWithIdentifier: forIndexPath: 方法,而较旧的教程和书籍(大多数)使用 tableView: dequeueReusableCellWithIdentifier:

如果你想用新的方式(-tableView: dequeueReusableCellWithIdentifier: forIndexPath)你需要添加[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];viewDidLoad 中,(或者在 storyboard/nib 中设置原型(prototype) cell reuse id,以及适本地设置细胞类型 - 基本应该适用于正常细胞)。

旧方法 (tableView: dequeueReusableCellWithIdentifier:) 通常后跟 if 语句,例如:

if(cell == nil) 
{
cell = [UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

(\\Configure the cell. . . 注释所在的位置)

虽然这是非常简单的东西,但公平地说,大多数教程确实教授旧方法,我想如果您没有注意到两者之间的细微差别,这可能会让初学者感到困惑 -tableView:dequeueReusableCell方法。显示新方法的教程是 here

关于ios - Signal SIGABRT 简单 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14799440/

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