2011-09-26 113 views
0

这可能是一些简单的错误,我似乎无法在我的代码中找到它。didSelectRowAtIndexPath引发异常

当过我在tableview中单击单元格,我得到一个异常

这是我的接口:

@interface MenuViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> 

@end 

我不使用XIB文件,所以这是我的loadView

- (void)loadView 
{ 
    UIView *myview = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.title = @"Menu"; 
    UITableView *tableViewMenuItems = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 150) style:UITableViewStyleGrouped]; 
    tableViewMenuItems.backgroundColor = [UIColor clearColor]; 
    tableViewMenuItems.delegate = self; 
    tableViewMenuItems.dataSource = self; 
    tableViewMenuItems.scrollEnabled = NO; 
    [myview addSubview:tableViewMenuItems]; 
    [tableViewMenuItems release]; 
    self.view = myview; 
    [myview release]; 
} 

这是选择行的代表方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    SendMessageViewController *sendMessageViewController = [[SendMessageViewController alloc] init]; 
    [self.navigationController pushViewController:sendMessageViewController animated:YES]; 
    [sendMessageViewController release]; 
} 

我的BT

#0 0x94e3c9c6 in __pthread_kill() 
#1 0x98079f78 in pthread_kill() 
#2 0x9806abdd in abort() 
#3 0x9588a921 in abort_message() 
#4 0x958881bc in default_terminate() 
#5 0x010ee23b in _objc_terminate() 
#6 0x958881fe in safe_handler_caller() 
#7 0x95888268 in std::terminate() 
#8 0x958892a0 in __cxa_throw() 
#9 0x010ee416 in objc_exception_throw() 
#10 0x00f9c0bb in -[NSObject(NSObject) doesNotRecognizeSelector:]() 
#11 0x00f0b966 in ___forwarding___() 
#12 0x00f0b522 in __forwarding_prep_0___() 
#13 0x0008c870 in -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]() 
#14 0x00082b05 in -[UITableView _userSelectRowAtPendingSelectionIndexPath:]() 
#15 0x0079c79e in __NSFireDelayedPerform() 
#16 0x00f7b8c3 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__() 
#17 0x00f7ce74 in __CFRunLoopDoTimer() 
#18 0x00ed92c9 in __CFRunLoopRun() 
#19 0x00ed8840 in CFRunLoopRunSpecific() 
#20 0x00ed8761 in CFRunLoopRunInMode() 
#21 0x011d21c4 in GSEventRunModal() 
#22 0x011d2289 in GSEventRun() 
#23 0x00023c93 in UIApplicationMain() 
#24 0x00002589 in main (argc=1, argv=0xbffff698) at main.m:14 

我在做什么错?

+0

什么是显示在源代码中的Xcode?在什么行app've停止了什么错误? – Nekto

+0

调试器在'didSelectRowAtIndexPath'中输入吗? – Nekto

回答

1

好吧发现我的问题:

在我的委托是这样算下来

MenuViewController *menuViewController = [[[MenuViewController alloc] init] autorelease]; 
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:menuViewController] autorelease]; 

到底我打电话说哪里发布对象的方法。所以我删除了autorelease,问题解决了。感谢所有的回应

2

看这句话

-[NSObject(NSObject) doesNotRecognizeSelector:]() 

它清楚地说,你拨打的确实在表格视图单元格时,点击不是在你的代码某处的方法。尝试在viewDidLoad和viewWill/DidAppear方法中搜索警告SendMessageViewController

+0

这使我朝着正确的方向 – Armand

0

确保您正在调用UIViewController的指定初始化程序;因为你没有用笔尖你应该调用:

[[SendMessageViewController alloc] initWithNibName: nil bundle: nil]; 

或者你可以简单地调用这个方法,在您的视图控制器的init方法。

如果这样不能解决问题,请在NSException上设置一个符号断点,让代码在问题点停下来,并希望给您更多信息。

另一方面 - 您为什么要创建容器的任何特定原因查看屏幕的大小?你会得到一个免费的设置。你应该能够将你的UITableView添加为视图控制器视图的子视图,这将有助于简化代码。或者只需使用UITableViewController。

+0

您也可以尝试不在UITableView上设置scrollEnabled并查看问题是否消失。 –

+0

我喜欢为容器设置容器,以便在屏幕上制作动画时,它使我的生活更容易进行未来的扩展,除此之外没有其他原因 – Armand