안녕하세요, 저는 스토리 보드에 4 개의 프로토 타입 셀을 사용합니다. 각 프로토 타입 셀에 대해 나는 내 레이블로 클래스 uitableviewCell을가집니다.프로토 타입 세포 uitableview
내 코드를 보면 :
섹션 0 섹션 1, 내가이가 내 레이블하지만, 섹션 2의 경우 0에서 datas가에서- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProfilCell";
static NSString *CellIdentifier1 = @"ProfilCell1";
static NSString *CellIdentifier2 = @"ProfilCell2";
static NSString *CellIdentifier3 = @"ProfilCell3";
static NSString *CellIdentifier4 = @"ProfilCell4";
if(indexPath.section == 0)
{
ProfilCell* cell =(ProfilCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.pseudoLabel.text=[[infoArray objectAtIndex:indexPath.row]valueForKey:@"pseudo"];
return cell;
}
if(indexPath.section == 1)
{
ProfilCell2* cell = (ProfilCell2*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
cell.textLabel.text= [[infoArray objectAtIndex:indexPath.row]valueForKey:@"status"];
return cell;
}
if(indexPath.section == 2)
{
switch (indexPath.row)
{
case 0:
{
ProfilCell3* cell =(ProfilCell3*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
cell.ageLabel.text= [[infoArray objectAtIndex:indexPath.row]valueForKey:@"age"];
return cell;
}
break;
case 1:
{
ProfilCell4* cell = (ProfilCell4*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier3];
cell.deptLabel.text= [[infoArray objectAtIndex:indexPath.row]valueForKey:@"localite"];
return cell;
}
break;
case 2:
{
ProfilCell5* cell = (ProfilCell5*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier4];
cell.membreLab.text= [[infoArray objectAtIndex:indexPath.row]valueForKey:@"membre"];
return cell;
}
break;
default:
break;
}
}
return nil;
}
: 내 배열이 나타납니다 왜
[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
이 될 수를 비어있는
이제 배열에 객체가 하나뿐이므로 indexPath에 0을 주면됩니다.
'if'문을 사용하지 않으면 'return cell'이 nil을 반환합니다. 원래 코드 게시와 다른 점은 무엇입니까? – GoZoner
하드 코딩 된 행이 아니고 더 많거나 적지 않은지 어떻게 알 수 있습니까? ... – skram