Jor*_*ith 9 iphone objective-c uibutton ipad ios
问题:当用户点击UITableViewCell中的UIButton时,该按钮只会在长按时突出显示,而不是快速点按.无论点击持续时间如何,此按钮都会突出显示所需的行为.
不幸的是:由于其他不需要的副作用,在任何UIScrollView或UITableView上将delaysContentTouches设置为NO都不是一个选项.
那么:我怎样才能解决这个问题 - 有没有办法将触摸转发到按钮,绕过delayedContentTouches值?
Mik*_*ika -1
在原型单元中将按钮的标签设置为“1”。
在 cellForRowAtIndexPath 中,您应该将 UIButton 链接到一个方法:
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchUpInside];
Run Code Online (Sandbox Code Playgroud)
然后在该方法中你要做的就是:
-(void) aMethod: (id) sender{
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.cartTableView];
NSIndexPath *indexPath = [self.cartTableView indexPathForRowAtPoint:buttonPosition];
if (indexPath != nil)
{
//Do your stuff
}
}
Run Code Online (Sandbox Code Playgroud)
这不会在运行代码之前增加任何延迟。
归档时间: |
|
查看次数: |
2120 次 |
最近记录: |