Can*_*ğlu 7 cocoa-touch uitableview ios ios7
我有一个自定义UITableViewCell
在我的iPhone应用程序,我有一个自定义的setSelected:animated
方法.我的应用程序在iPhone上完美运行,然而,我开始将我的应用程序移植到iPad.我已经复制了完全相同的故事板,没有改变任何东西,但现在我的setSelected:animated
方法在我选择我的单元格时被调用两次(具有相同的参数).我可以通过检查iPad等来"处理"这种情况,但这将是一个不好的做法.可能是因为它在iPhone上被称为一次,而在iPad上被称为两次?(iOS 7.0.3)表视图的属性完全相同(我复制了iPhone故事板文件).
这是相关代码:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
isSelected = selected;
[self setNeedsDisplay];
if(selected){
SocialMatchAppDelegate *del = (SocialMatchAppDelegate*)[UIApplication sharedApplication].delegate;
del.selectedUser = self.user;
[del.resultViewController performSegueWithIdentifier:@"viewProfile" sender:self];
}
}
Run Code Online (Sandbox Code Playgroud)
我想如果您使用iPad,这是正常现象。
为了停止获取多个“ setSelected:YES”或多个“ setSelected:NO”,您要做的就是:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
现在,在任何单元格上单击1可为您提供:
- (void)setSelected:(BOOL)selected
你的消息来源是在哪里调用的?
如果是在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
用这个代替
[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
归档时间: |
|
查看次数: |
2340 次 |
最近记录: |