i am a new programmer of Iphone App….. i wants three cells in table (which are different height)
i write the code for this task..and output is satisfactory…… but i don’t know.. this is right method or not…..
thanks in advance….. 🙂
CGRect frame=CGRectMake(5, 43, 311, 363);
UITableView *table=[[UITableView alloc]initWithFrame:frame style:UITableViewStylePlain];
table.dataSource=self;
table.delegate=self;
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *)indexPath
{
static int counter=1;
if(counter==1)
{
counter=counter +1;
return 163;
}
else if(counter ==2)
{
counter=counter +1;
return 80;
}
else
{
counter=counter +1;
return 60;
}
if(counter==4)
{
counter=1;
}
}
No, this isn’t right. Use
indexPath.rowinstead of yourcountervariable. This will be the row number your delegate is being asked about. When scrolling upwards, for example, you may not get the expected results with your current code.