iPhone:didSelectRowAtIndexPath未被调用 [英] iPhone: didSelectRowAtIndexPath not invoked

查看:94
本文介绍了iPhone:didSelectRowAtIndexPath未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道之前提到的这个问题,但那里的决议并不适用。我有一个UINavigationController,它使用IB设置嵌入式UITableViewController。在IB中,UITableView的委托和dataSource都设置为我的UITableViewController的派生。已使用XCode的UITableViewController类模板添加此类。没有自定义UITableViewCell,并且表视图仅使用具有单个标题的默认普通样式。

I know this issue being mentioned before, but resolutions there didn't apply. I'm having a UINavigationController with an embedded UITableViewController set up using IB. In IB the UITableView's delegate and dataSource are both set to my derivation of UITableViewController. This class has been added using XCode's templates for UITableViewController classes. There is no custom UITableViewCell and the table view is using default plain style with single title, only.

好吧,在模拟器中,列表正确呈现,其中两个元素由dataSource,因此dataSource正确链接。如果我在IB中删除了dataSource的出口链接,则会呈现一个空表。

Well, in simulator the list is rendered properly, with two elements provided by dataSource, so dataSource is linked properly. If I remove the outlet link for dataSource in IB, an empty table is rendered instead.

当我点击这两个项目中的一个时,它会闪烁蓝色并且GDB遇到 __ forwarding __ 在 UITableView :: _ selectRowAtIndexPath 的范围内。它没有达到我的非空方法didSelectRowIndexPath中设置的断点。我检查了参数和方法的名称,以排除导致不同选择器的拼写错误。

As soon as I tap on one of these two items, it is flashing blue and the GDB encounters interruption in __forwarding__ in scope of a UITableView::_selectRowAtIndexPath. It's not reaching breakpoint set in my non-empty method didSelectRowIndexPath. I checked the arguments and method's name to exclude typos resulting in different selector.

我最近没有成功设置委托是否正确,但是因为它被设置为等同于从同一个类获得两个元素的dataSource,我希望它设置得当。那么,出了什么问题?

I recently didn't succeed in whether delegate is set properly, but as it is set equivalently to dataSource which is getting two elements from the same class, I expect it to be set properly. So, what's wrong?

我正在运行iPhone / iPad SDK 3.1.2 ......但是在模拟器中尝试使用iPhone SDK 3.1。

I'm running iPhone/iPad SDK 3.1.2 ... but tried with iPhone SDK 3.1 in simulator as well.

编辑:这是我的UITableViewController派生的代码:

This is the code of my UITableViewController derivation:

#import "LocalBrowserListController.h"
#import "InstrumentDescriptor.h"

@implementation LocalBrowserListController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self listLocalInstruments];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
    [super viewDidUnload];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [entries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

    if ( ( [entries count] > 0 ) && ( [indexPath length] > 0 ) )
        cell.textLabel.text = [[[entries objectAtIndex:[indexPath indexAtPosition:[indexPath length] - 1]] label] retain];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if ( ( [entries count] > 0 ) && ( [indexPath length] > 0 ) )
    {
        ...
    }
}

- (void)dealloc {
    [super dealloc];
}

- (void) listLocalInstruments {
    NSMutableArray *result = [NSMutableArray arrayWithCapacity:10];

    [result addObject:[InstrumentDescriptor descriptorOn:[[NSBundle mainBundle] pathForResource:@"example" ofType:@"idl"] withLabel:@"Default 1"]];
    [result addObject:[InstrumentDescriptor descriptorOn:[[NSBundle mainBundle] pathForResource:@"example" ofType:@"xml"] withLabel:@"Default 2"]];

    [entries release];
    entries = [[NSArray alloc] initWithArray:result];
}

@end


推荐答案

好吧,在尝试保留UITableView实例的委托只是为了检查内存泄漏是否成功之后,我调查了这个问题并偶然发现了一些关于如何使用分离的NIB组合视图和控制器的教程,就像我在这里一样。本教程最终让我做到了这一点:

Well, after trying to retain the delegate of UITableView instance just to check for leaking memory with success, I investigated on that issue and stumbled over some tutorials on how to combine views and controllers using detached NIBs as I do here. This tutorial finally made me do the trick:

组合视图控制器

专注于错误详细信息有两个UITableViewControllers ...一个在主NIB中设置为选项卡式导航控制器的根控制器,另一个在引用的NIB中用于提供原始UITableView实例。

Focusing on error in detail there were two UITableViewControllers ... one in main NIB set as root controller for a tabbed Navigation controller and a second time in referenced NIB used to provide a raw UITableView instance instead.

这篇关于iPhone:didSelectRowAtIndexPath未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆