我在我的视图中使用了三个表,并使用标签将它们分开。在我的第二个表格视图中,我制作了一个自定义 uitableview 并在其中添加标签和按钮。
这是我在 cellforrowatindexpath 中写的按钮
followingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[followingButton addTarget:self action:@selector(followingButtonpressed:)forControlEvents:UIControlEventTouchUpInside];
[followingButton setImage:[UIImage imageNamed:@"following12.png"] forState:UIControlStateNormal];
following.tag=indexpath.row;
[followingButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
followingButton.frame = CGRectMake(220.0 ,20.0, 100, 40.0);
[cell.contentView addSubview:followingButton];
======
-(void)followingButtonpressed:(id)sender
{
UIView *contentView1 = (UIView *)[sender superview];
UITableViewCell *cell1= (UITableViewCell *)[contentView1 superview];
NSIndexPath *indexPath1 = [followingTable indexPathForCell:cell1];
[sender tag];
NSLog(@"sender tag --%d",[sender tag]);
// UIButton *button = (UIButton *)sender;
// UITableViewCell *cell = (UITableViewCell*)[button superview];
UIButton *tempButtom = (UIButton *)[cell1 viewWithTag:[sender tag]];
[tempButtom setImage:[UIImage imageNamed:@"following_off12.png"]
forState:UIControlStateNormal];
}
但是它崩溃了,我无法更改所选按钮的图像,请帮助