I am trying this code to set width of cell when table is load. but it is properly work in didSelectRowAtIndexPath method but not work in cellForRowAtIndexPath help me.
cell.frame = CGRectMake(50, cell.frame.origin.y, 275, 44)
so when we click on cell it will change the width not directly when it is load.. yes i have tried also if (cell == nil) { cell = [[UITableViewCell alloc] initWithFrame:CGRectMake( 30, cell.frame.origin.y, 275, 44)]; }
see my all code of table methods
#pragma mark - Table Method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 7;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ((section == 0) ?
3 : (section == 1) ?
1 : (section == 2) ?
1 : (section == 3) ?
2 : (section == 4) ?
1 : (section == 5) ?
1 : (section == 6) ?
1 : 1);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithFrame:CGRectMake( 30, cell.frame.origin.y, 275, 44)];
}
if (indexPath.section == 0) {
cell.frame = CGRectMake(50, cell.frame.origin.y, 275, 44);
return cell;
}
if (indexPath.section >= 1)
{
cell.frame = CGRectMake( 30, cell.frame.origin.y, 200, 44);
cell.textLabel.text=@"Dhaval";
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell =[tableview cellForRowAtIndexPath:indexPath];
cell.frame = CGRectMake(50, cell.frame.origin.y, 275, 44);
}