自定義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.
