朋友, 我想在xib文件的表格視圖中添加多個自定義單元格。 詳細我想爲表中的每一行添加不同的單元格我試着下面的代碼,但似乎不工作我只能自定義一個單元格中的所有行在tableview代碼是如下我已經嘗試過兩個代碼 code1是下面在xib文件的每一行中使用uitableview自定義多個單元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
[email protected]"tablecell";
tablecell *cell = (tablecell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"tablecell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
[email protected]"gopi";
return cell;
if (indexPath.row==1)
{
NSString *identifier1;
[email protected]"gopicell";
gopicell *cell1=(gopicell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"gopicell" owner:self options:nil];
cell1=[nib objectAtIndex:0];
}
[email protected]"sabari";
return cell1;
}
}
,而只會顯示一個自定義單元格,所以我想這碼碼2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
if (indexPath.row==0)
{
[email protected]"tablecell";
tablecell *cell = (tablecell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"tablecell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
[email protected]"gopi";
return cell;
}
else if(indexPath.row==1)
{
[email protected]"gopicell";
gopicell *cell1=(gopicell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"gopicell" owner:self options:nil];
cell1=[nib objectAtIndex:0];
}
[email protected]"sabari";
return cell1;
}
return nil;
}
我知道這種說法是錯誤的,但我不知道該怎麼回到這裏,如果我已經是它可以自定義每行有多個單元格
檢查此鏈接 http://stackoverflow.com/questions/5575125/adding-multiple-custom-cells-in-uitableview[enter此處鏈接說明] [1] 希望它有助於。 [1]:http://stackoverflow.com/questions/5575125/adding-multiple-custom-cells-in-uitableview –
可以附加的圖像。你到底想要什麼? –