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