UITableView 从不调用 didSelectRowAtIndexPath

Posted

技术标签:

【中文标题】UITableView 从不调用 didSelectRowAtIndexPath【英文标题】:UITableView never call didSelectRowAtIndexPath 【发布时间】:2013-06-25 14:48:47 【问题描述】:

我正在使用 UITableViewJson 解析。

 -(void) connectionDidFinishLoading :(NSURLConnection *) connection

     self.resultTable.delegate = self;

     self.resultTable.dataSource = self; 

我正在解析数据并设置UITableView's delegatedatasource self。

当我编译该程序时,我用jSON 解析的数据会正确无误。

主要问题是:当我尝试进入行表时,调试器永远不会出现

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

我尝试了很多东西(包括 segue 等),但我无法通过用手指敲击来选择任何单元格的行。真的感觉我喜欢点击文本字段...

有人知道这个问题吗?

最好的问候...

-编辑-

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    _userSettings = [NSUserDefaults standardUserDefaults];

    static NSString *CellIdentifier =@"CellID";


    ResultNearbyList *cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    [cell.profilePictureIndicator startAnimating];

        if (cell == nil) 
            cell = [[ResultNearbyList alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        

        cell.userProfilePicture.profileID = [userFBIDArray objectAtIndex:indexPath.row];

    self.userDOBStr = [userDOB objectAtIndex:indexPath.row];

    self.userGenderStr = [userGender objectAtIndex:indexPath.row];

        [cell.profilePictureIndicator stopAnimating];

        [_listNearbyView stopAnimating];


        cell.userNickName.text = [userNickNameArray objectAtIndex:indexPath.row];

        NSString *fullName = [userFullNameArray objectAtIndex:indexPath.row];


        NSString* fullNameUTF8 = [NSString stringWithUTF8String:[fullName cStringUsingEncoding:NSUTF8StringEncoding]];


        //NSString *fullNameUTF8 = [NSString stringWithCString:[fullName cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];


        cell.userFullName.text = fullNameUTF8;

        NSString *userCityCountry = [userCountryArray objectAtIndex:indexPath.row];

        userCityCountry = [userCityCountry stringByAppendingString:@"/"];

        userCityCountry = [userCityCountry stringByAppendingString:[userCityArray objectAtIndex:indexPath.row]];

        cell.userCityCountry.text = userCityCountry;

        NSString *userDestination = [userDistanceArray objectAtIndex:indexPath.row];

        NSRange range = [userDestination rangeOfString:@"."];

        NSString *substring = (range.location != NSNotFound) ? [userDestination substringToIndex:range.location] : nil;

        substring = [substring stringByAppendingString:@" km"];

        if([substring intValue] == 0)
        
            substring = (range.location != NSNotFound) ? [userDestination substringFromIndex:range.location] : nil;

            substring = [substring substringWithRange:NSMakeRange(0, 4)];

            substring = [substring stringByAppendingString:@" m"];
        



        cell.userDistance.text = substring;

        return cell; 


截图:1

【问题讨论】:

你能展示你的 cellForRowAtIndexPath 代码吗? 长按单元格是否高亮? @micantox,我编辑了。韦恩,不。它没有高光... 桌子肯定有触摸事件吗?即你可以滚动它吗? 是的,我现在正在添加屏幕截图。 【参考方案1】:

转到您的故事板,选择 UITable 并检查选择是否设置为“单选”。另请注意复选标记“触摸时显示选择”

【讨论】:

它设置了单选并检查了在触摸时显示选择:( 我什么都试过了,除了在connectionDidFinishLoading之后处理数组中的所有数据并推送另一个viewController。我认为使用 GDC 和 TableView 会产生问题。在同一个 UIView 中处理 NSURLConnection 和 Tableview 有什么好的例子吗?【参考方案2】:

我发现了我的错误。我缺少的部分是,我只是将objective-c 类文件添加为UIViewController 来创建Cell 原型视图。比我更改了 UIViewController -> UITableViewCell。但是手动更改为类类型,并没有添加以下实例:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) 
        // Initialization code
    
    return self;


- (void)setSelected:(BOOL)selected animated:(BOOL)animated

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

当我将这些实例设置为我的 UItableViewCell 类实现文件时,问题已解决:)

感谢您的所有帮助...

【讨论】:

以上是关于UITableView 从不调用 didSelectRowAtIndexPath的主要内容,如果未能解决你的问题,请参考以下文章

UITableView 方法“indexPathForRowAtPoint:”的奇怪行为

永远不会调用cellForRowAtIndexPath

没有 UITableViewController 的 UIRefreshControl 不调用选择器

在内存警告后调用 viewdidunload 后视图从不重新加载(viewdidload 从不调用)

如何为 didSelectRowAtIndexPath 中的选定笔尖单元触发某些 segue

为啥 fusedLocationProviderClient.getLastLocation 从不调用 OnSuccessListener?