2017-04-04 2 views
0

Ich habe mit UITableView s in iOS gearbeitet, aber etwas wirklich komisches scheint diesmal zu passieren. Ich brauche einen neuen Knopf UIViewController auf die Auswahl eines UITableViewCell. Alles funktioniert gut außer, manchmal, wenn ich zurück zu UIViewController, die UITableView enthält und versuchen, und wählen Sie eine andere UITableViewCell als die vorherige, wählt es automatisch die UITableViewCell, die zuvor angezapft wurde. Ich weiß, dass es für einige von euch lustig klingen mag, aber es passiert mir und beschäftigt mich seit mehr als einem Tag. Jede Hilfe wäre sehr hilfreich. Ich weiß, es ist etwas wirklich Dummes, aber ich kann es nicht erkennen.Weird UITableView Verhalten beim Tippen auf eine Zelle?

Hier ist, wie die ‚DidSelectRowAtIndexPath‘ sieht aus wie -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    NSLog(@"row - %ld", (long)indexPath.row); 
    Notification *obj = [objects objectAtIndex:indexPath.row]; 
    if (obj.post.post_id) { 
     FeedViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"postsView"]; 
     [self.navigationController pushViewController:vc animated:YES]; 
     vc.postID = obj.post.post_id; 
     self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; 
    } 
    else 
    { 
     UserProfileViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"userProfile"]; 
     vc.username = obj.user.username; 
     [self.navigationController pushViewController:vc animated:YES]; 
     self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]; 
    } 
} 

Nach stundenlang Debuggen konnte ich das sehen, auf dem Rückweg die beabsichtigte UITableViewCell nie in der Standard-Weise hervorgehoben wird es soll und sobald die Berührung losgelassen wird, wird die "alte" UITableViewCell ausgewählt und führt ihre Aktion aus.

UPDATE

cellForRowAtIndexPath so geht -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
NotificationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"notificationCell"]; 
Notification *obj = [objects objectAtIndex:indexPath.row]; 
cell.cellIndex = (int)indexPath.row; 
cell.delegate = self; 
cell.userImage.layer.cornerRadius = cell.userImage.frame.size.width/2.0f; 
[cell.userImage sd_setImageWithURL:[NSURL URLWithString:obj.user.photo] 
        placeholderImage:[UIImage imageNamed:@""]]; 
cell.timeLabel.text = obj.timestamp; 
cell.descriptionLabel.text = [@"@" stringByAppendingString:[[obj.user.username stringByAppendingString:@" "] stringByAppendingString:obj.message]]; 

cell.descriptionLabel.userHandleLinkTapHandler = ^(KILabel *label, NSString *string, NSRange range) { 
    NSLog(@"User tapped %@", string); 
    [self didTapOnCallout:string]; 
}; 

cell.descriptionLabel.hashtagLinkTapHandler = ^(KILabel *label, NSString *string, NSRange range) { 
    NSLog(@"Hashtag tapped %@", string); 
    [self didTapOnHashTag:string]; 
}; 

cell.descriptionLabel.urlLinkTapHandler = ^(KILabel *label, NSString *string, NSRange range) { 
    NSLog(@"URL tapped %@", string); 
    [self didTapOnURL:string]; 
}; 

return cell; 
} 

I Verwendung von KILabel mache für Hähne auf URLs und Hashtags zu hören.

+1

Aktualisieren Sie Ihre Frage mit dem Code. –

+0

Der Code @RajeshkumarR wurde aktualisiert. – genaks

+1

Haben Sie einen 'didDeselectRowAtIndexPath' im View-Controller? (Ich habe manchmal Fehler mit diesen Namen gemacht.) –

Antwort