【发布时间】:2010-02-21 12:01:22
【问题描述】:
我知道之前提到过这个问题,但那里的解决方案不适用。我有一个使用 IB 设置的带有嵌入式 UITableViewController 的 UINavigationController。在 IB 中,UITableView 的委托和数据源都设置为我派生的 UITableViewController。此类已使用 XCode 的 UITableViewController 类模板添加。没有自定义 UITableViewCell 并且表格视图仅使用带有单个标题的默认普通样式。
好吧,在模拟器中,列表正确呈现,两个元素由 dataSource 提供,因此 dataSource 正确链接。如果我在 IB 中删除 dataSource 的出口链接,则会呈现一个空表。
只要我点击这两个项目之一,它就会闪烁蓝色,并且 GDB 在__forwarding__ 范围内遇到UITableView::_selectRowAtIndexPath 的中断。它没有达到在我的非空方法 didSelectRowIndexPath 中设置的断点。我检查了参数和方法的名称以排除导致不同选择器的拼写错误。
我最近未能成功设置委托是否正确,但由于它设置为等效于从同一类获取两个元素的 dataSource,我希望它设置正确。那么,怎么了?
我正在运行 iPhone/iPad SDK 3.1.2 ...但也尝试在模拟器中使用 iPhone SDK 3.1。
编辑:这是我的 UITableViewController 派生的代码:
#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
【问题讨论】:
标签: iphone uitableview