In my app i am customizing my table view using this method:-
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
// }
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(indexPath.row == 0)
{
button1=[[UIButton alloc] initWithFrame:CGRectMake(15,5,100,87)];
[button1 setImage:[UIImage imageNamed:@"BUTTON.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:self.button1];
button2=[[UIButton alloc] initWithFrame:CGRectMake(135,5,100,87)];
[button2 setImage:[UIImage imageNamed:@"TURN OFF.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button2];
}
else if(indexPath.row == 1)
{
button3=[[UIButton alloc] initWithFrame:CGRectMake(15,5,100,87)];
[button3 setImage:[UIImage imageNamed:@"JUMP.png"] forState:UIControlStateNormal];
[button3 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button3];
button4=[[UIButton alloc] initWithFrame:CGRectMake(135,5,100,87)];
[button4 setImage:[UIImage imageNamed:@"CLOSE.png"] forState:UIControlStateNormal];
[button4 addTarget:self action:@selector(ClickTo:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:button4];
}
else
{
// Do something here
}
return cell;
}
I am adding 2 buttons in one row and adding images to each button.I have a button,Now what i want is that when i click on the button i want to change the images present in the button and also the table view must change its position within the view.How to achieve this .Did on button click event i have to give new frame to table view and also add new images to the buttons and then call reload data for the table view .I have tried this but nothing happened.What could be the problem?please help.Any help will be appreciated.
Thanks,
Christy
In didselectrowatindexpath take the selectedIndex.Then using the reloadData method you can reload it.And in the cellforRowatIndexPath you have to change the button Image.