UITableView上button的點選事件(一)
阿新 • • 發佈:2019-01-24
在UITableView中新增button,button點選改變背景圖片時,發現按下時間短的話,無法改變背景圖片,經過一番奮鬥,終於找到了原因。
iOS6的UITableViewCell 子檢視(subviews)的容器是UITableViewCellContentView
iOS7的UITableViewCell 子檢視(subviews)的容器是UITableViewCellScrollView
由於iOS7中添加了滑動後出現編輯按鈕的操作,所以使用scrollView來處理,UITableViewCellScrollView有對觸控的相應處理,導致按鈕的點選效果被遮蔽了。
1.設定tableView.delaysContentTouches = NO;
2.同時在(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath代理方法中對scrollview把延遲觸控設定為NO即可
iOS6的UITableViewCell 子檢視(subviews)的容器是UITableViewCellContentView
iOS7的UITableViewCell 子檢視(subviews)的容器是UITableViewCellScrollView
由於iOS7中添加了滑動後出現編輯按鈕的操作,所以使用scrollView來處理,UITableViewCellScrollView有對觸控的相應處理,導致按鈕的點選效果被遮蔽了。
1.設定tableView.delaysContentTouches = NO;
2.同時在(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath代理方法中對scrollview把延遲觸控設定為NO即可
for (id obj in cell.subviews) {
if ([NSStringFromClass([obj class])isEqualToString:@"UITableViewCellScrollView"]){
UIScrollView *scroll = (UIScrollView *) obj;
scroll.delaysContentTouches = NO;
break;
}
}
不過,暫時沒發現方法2的好處,似乎只要寫方法1就可以控制了···