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.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM