I have a custom UITableViewCell
on my iPhone app for which I have a custom setSelected:animated
method. My app works perfectly on iPhone, however, I started to port my app to iPad. I've copied the exact same storyboard, haven't changed anything, but now my setSelected:animated
method is called twice (with the same parameters) when I select my cell. I could "handle" this case by checking if iPad etc. but it would be a bad practice. What could be the reason that it's called once on iPhone but twice on iPad? (both iOS 7.0.3) The table view's properties are exactly the same (I've copied the iPhone storyboard file).
Here is the relevant code:
- (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];
}
}
I suppose this is a normal behavior if you're using iPad.
In order to stop getting multiple "setSelected:YES" or multiple "setSelected:NO", all you have to do is this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Now, 1 click on any cell gives you:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With