섹션을 만들면 오류가 발생합니다.UITableview 섹션 오류 - objc_msgSend
이미 섹션 색인을 0과 1로 설정하려고 시도했지만 도움이되지 않았습니다.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier1 = @"Cell1";
if(indexPath.section == 1) {
if(indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.text = @"test 1";
}
return cell;
}
else if(indexPath.row == 1) {
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil) {
cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
cell1.text = @"test 2";
}
return cell1;
}
}
else if(indexPath.section == 2) {
if(indexPath.row == 0) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.text = @"test 1";
}
return cell;
}
else if(indexPath.row == 1) {
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil) {
cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
cell1.text = @"test 2";
}
return cell1;
}
}
}
섹션은 실제로 1에서 시작됩니다. '- (NSInteger) numberOfSectionsInTableView : (UITableView *) tableView' 함수는 항상 적어도 '1'이 아닌 '0'을 반환해야합니다. 또한 충돌을 일으킬 수 있습니다. – Jake
실제로 항상 1 섹션이지만 indexpath의 첫 번째 섹션 번호는 0입니다. indexPath.section == 0 -> 첫 번째 섹션 – drvdijk
+1 또한 컴파일러는 (비어 있음) 함수를 통해 경로 중 하나가 아무 것도 반환하지 않는다는 사실에 대해 경고해야합니다. – frankodwyer