私はこのエラーを探していましたが、同様の動作をするいくつかの投稿を見つけましたが、問題を解決する解決策はありませんでした.
セクションを持つ UITableViewController (SB で静的として宣言されている) があります: セクション 0 (レシピ) は 4 つのセルで静的であり、セクション 1 (フレーバー) は動的である必要があります
これは私がテストに使用しているコードです:
- (void)viewDidLoad {
[super viewDidLoad];
rows = [[NSMutableArray alloc] initWithArray:@[@"test",@"test",@"test",@"test",@"test",@"test",@"test"]];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 4;
break;
case 1:
return rows.count;
break;
default:
break;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
switch (indexPath.section) {
case 0:
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell)
{
// create a cell
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.textLabel.text = [rows objectAtIndex:indexPath.row];
return cell;
default:
break;
}
return cell;
}
実行時に発生するエラーは次のとおりです: 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
私はどこか小さな何かを見逃していることを知っています.誰かが私を助けることができますか?
本当にありがとう