gpt4 book ai didi

ios - 返回表中的单元格数会产生 NSInternalInconsistenceyException

转载 作者:行者123 更新时间:2023-11-28 20:00:22 24 4
gpt4 key购买 nike

尝试在我的表格中添加一个包含 6 个单元格的部分。我只有一些基本代码,它无法编译给我“'UITableView dataSource 必须从 tableView:cellForRowAtIndexPath:' 返回一个单元格”。我相信这与未设置数据源有关,但我不确定。这是代码:

- (void)viewDidLoad
{
[super viewDidLoad];
germanMakes = @[@"Mercedes-Benz", @"BMW", @"Porsche",
@"Opel", @"Volkswagen", @"Audi"];

// 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
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return germanMakes.count;
}

最佳答案

您必须实现所考虑的方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

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

cell.textLabel.text = germanMakes[indexPath.row];

return cell;
}

关于ios - 返回表中的单元格数会产生 NSInternalInconsistenceyException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24465007/

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