cellForRowAtIndexPath 대리자 방식으로 반환하기 위해 셀을 초기화하려면 어떻게해야합니까?cellForRowAtIndexPath에서 두 개의 다른 셀 반환
var i가 있다고 가정합니다. i는 0 또는 1이 될 수 있습니다. 는 : 그래서
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
id cell=nil;
switch (i) {
case 0:{
static NSString *[email protected]"RecommendTableCellIdentifier";
RecommendTableCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[RecommendTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
dataRow=[dataList objectAtIndex:[indexPath row]];
[cell addContent:dataRow];
[cell.wantToSeeButton setTag:[indexPath row]];
[cell.wantToSeeButton addTarget:self action:@selector(iWantToSeeClicked:) forControlEvents:UIControlEventTouchUpInside];
}
break;
case 1:{
static NSString *[email protected]"WantTableCellIdentifier";
WantTableCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[WantTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
dataRow=[dataList objectAtIndex:[indexPath row]];
[cell addContent:dataRow];
[cell.wantToSeeButton setTag:[indexPath row]];
[cell.wantToSeeButton addTarget:self action:@selector(iWantToSeeClicked:) forControlEvents:UIControlEventTouchUpInside];
}
break;
default:
break;
}
return cell;
}
모두 CustomCellA
및 B는 클래스 XIB로 정의된다.
어떻게해야합니까? 감사합니다.
'break; 앞에 사용자 셀을'id 셀 '에 할당하십시오. ie 0 경우 셀 = recommendTableCell이고 1이면 cell = wantTableCell입니다. – Akhilrajtr
또는 각 if if 레그에서'cell'을 리턴합니다. 문제는 거기에 정의 된 세 가지 다른 버전의 '셀'을 가지고 있으며 두 가지를 설정했지만 세 번째 버전을 반환한다는 것입니다. –