friends, i want to add more than one customised cell in a table view in xib file. In detail i want to add different cells for each row in table i tried the below code but seems to be not working i can only customise one cell for all the rows in tableview code is as below i have tried two codes code1 is as below
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
identifier=@"tablecell";
tablecell *cell = (tablecell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"tablecell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
cell.name.text=@"gopi";
return cell;
if (indexPath.row==1)
{
NSString *identifier1;
identifier1=@"gopicell";
gopicell *cell1=(gopicell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"gopicell" owner:self options:nil];
cell1=[nib objectAtIndex:0];
}
cell1.gopilabel.text=@"sabari";
return cell1;
}
}
It displays only one customised cell so i tried this code code2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier;
if (indexPath.row==0)
{
identifier=@"tablecell";
tablecell *cell = (tablecell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"tablecell" owner:self options:nil];
cell=[nib objectAtIndex:0];
}
cell.name.text=@"gopi";
return cell;
}
else if(indexPath.row==1)
{
identifier=@"gopicell";
gopicell *cell1=(gopicell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell1==nil)
{
NSArray *nib=[[NSBundle mainBundle]loadNibNamed:@"gopicell" owner:self options:nil];
cell1=[nib objectAtIndex:0];
}
cell1.gopilabel.text=@"sabari";
return cell1;
}
return nil;
}
i know this statement is wrong but i do not know what to return here if i have is it possible to customise more than one cell for each row