UITableview Problem with button image
my problem is i have one tableview displaying four cells, in those cells i have one cutom button also. By clicking on that button the button imag开发者_JAVA技巧e has to be changed like checkmark image.
i tried but not getting properly. my req is if i click on cell at index zero that index button image has to be changed.
can anyone help me on this.
Thanks in advance.
write the selectedIndex in .h file
- (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(selectedindex==indexPath.row){
cell.accessoryType=UITableViewCellAccessoryCheckmark;
//here you can change the backgroundimage.
button]setbackgroundImage:[UIImage imageNamed:@"1.Jpg"];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedIndex=indexPath.row;
[tableView reloadData];
}
you need to do two things
You need to pass a msg to button
[comboButton setBackgroundImage:[UIImage imageNamed:@"firstImage.png"] forState:UIControlStateNormal] [comboButton setBackgroundImage:[UIImage imageNamed:@"second.png"] forState:UIControlStateHighlighted]
and in tableView delegate method tableView:didSelectRowAtIndexPath: set the button state to Highlighted
精彩评论