簡體   English   中英

點擊單元格時出現怪異的UITableView行為嗎?

[英]Weird UITableView behaviour while tapping on a cell?

我之前在iOS中使用過UITableView ,但是這次似乎確實發生了一些奇怪的事情。 我需要在選擇UITableViewCell推送一個新的UIViewController 一切正常,除了有時,當我彈出包含UITableViewUIViewController並嘗試選擇與上一個不同的UITableViewCell ,它會自動選擇之前點擊的UITableViewCell 我知道對某些人來說這聽起來很可笑,但它正在發生在我身上,並且困擾了我超過一天。 任何幫助將大有幫助。 我知道這確實很愚蠢,但我似乎無法發現它。

這是'didSelectRowAtIndexPath'的樣子-

- (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];
    }
}

經過數小時的調試,我能夠看到,回來時,預期的UITableViewCell從未以應有的默認方式突出顯示,並且一旦釋放觸摸,便選擇了“舊的” UITableViewCell並執行其操作。

UPDATE

cellForRowAtIndexPath像這樣-

- (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;
}

我正在使用KILabel來監聽URL和主題標簽的點擊。

看來這是KILabel庫中的一個錯誤,我用來檢測對標簽和URL的點擊。

如果您遇到類似的問題, 請轉至此處-https: //github.com/Krelborn/KILabel/issues/57

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM