Hi, i have one button with image for selection in UITableviewCell.i have added button action as toggleButton method.if i touch button in particular Cell, the image of Button of Corresponding tablecell is changed.but i when i scroll tableview the changed image is in another cell.how can i avoid it?please see my code….will you tell what i have to do..?i don't want to use did select method in which i have to do other Operation.any help please?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
onButton = [UIButton buttonWithType:UIButtonTypeCustom];
onButton.tag = 1;
onButtonView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 50)];
onButtonView.tag = 2;
onButtonView.image = [UIImage imageNamed:@"NotSelected.png"];
[onButton setBackgroundImage:[onButtonView.image stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
[cell addSubview:onButton];
[onButton addTarget:self action:@selector(toggleButton:) forControlEvents: UIControlEventTouchUpInside];
[onButtonView release];
}
return cell;
}