Fork me on GitHub

uitableviewcell自定义按钮&& 让编辑状态下的UITableViewCell响应点击事件,不改变背景色

自定义uitableviewcell怎样实现跳转

一个自定义UITableViewCell,里面包含一个button, 点击button跳转到其它视图:

 

UIButton *btn =  [ retain];
btn.tag = indexPath.row;
[btn addTarget:self action:@selector(响应函数:)
     forControlEvents:UIControlEventTouchUpInside];

 

在tableview的编辑状态下:[self.tableview setEditing:YES animated:NO],令cell响应点击事件不会变颜色,但能响应事件,方法如下:


1.在cellForRowAtIndexPath中,对新生成的cell添加一个背景view:(将cell在选择时背景置为白色)

  UIView *aVIew = [[[UIView alloc]initWithFrame:cell.frame]autorelease];

 aView.backgroundColor = [UIColor whiteColor];

 cell.selectedBackgroundView = aView;


2.在响应点击事件didSelectRowAtIndexPath中添加下面代码:(将cell上contentView背景在选择时置为白色,将contentView上textlabel在选择时背景置为白色)

  [self.tableView cellForRowAtIndexPath:indexpath].textLabel.backgroundColor = [UIColor whiteColor];

 [[self.tableView cellForRowAtIndexPath:indexpath].contentView setBackgroundColor:[UIColor whiteColor]];



因此,cell上面包含contentview,contentView上面包含textlabel.

posted on 2012-02-29 09:19  pengyingh  阅读(4866)  评论(0编辑  收藏  举报

导航