UITableView-点击单元格并获取下一个视图
我在 TableViewController 中输入下一个视图时遇到问题。 当我单击单元格时,我看到 NSLog 文本,但没有任何操作,也没有第二个视图。 这意味着程序进入方法但不执行任何操作。我有什么错? 我正在测试但没有得到任何解决方案。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
NSLog(@"Index 0");
AudioViewController *audioviewcontroller = [[AudioViewController alloc] initWithNibName:@"AudioViewController" bundle:nil];
[self.navController pushViewController:audioviewcontroller animated:YES];
[audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==1) {
NSLog(@"Index 1");
DisplayViewController *displayviewcontroller = [[DisplayViewController alloc] initWithNibName:@"DisplayViewController" bundle:nil];
[self.navController pushViewController:displayviewcontroller animated:YES];
[displayviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==2) {
LichtViewController *lichtviewcontroller = [[LichtViewController alloc] initWithNibName:@"LichtViewController" bundle:nil];
[self.navController pushViewController:lichtViewController animated:YES];
[lichtviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
NSLog(@"Index 2");
}
if (indexPath.row==3) {
NSLog(@"Index 3");
ProjektorViewController *projektorviewcontroller = [[ProjektorViewController alloc] initWithNibName:@"ProjektorViewController" bundle:nil];
[self.navController pushViewController:projektorviewcontroller animated:YES];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
[projektorviewcontroller release];
}
}
此外,我尝试了这段代码:
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
[currentView removeFromSuperview];
UIView* audioView= audioviewcontroller.view;
[theWindow addSubview:audioView];
[self.navController pushViewController:audioviewcontroller animated:YES]; [audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
我没有收到任何警告,但出现崩溃,调试器控制台显示:
2011-10-26 10:01:59.344 subview[971:207] -[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880
2011-10-26 10:01:59.346 subview[971:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dcf5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f23313 objc_exception_throw + 44
2 CoreFoundation 0x00dd10bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d40966 ___forwarding___ + 966
4 CoreFoundation 0x00d40522 _CF_forwarding_prep_0 + 50
5 UIKit 0x0047a6ff -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 111
6 UIKit 0x0047a3b0 -[UITableViewRowData invalidateAllSections] + 66
7 UIKit 0x00331d23 -[UITableView(_UITableViewPrivate) _updateRowData] + 113
8 UIKit 0x0032d65c -[UITableView noteNumberOfRowsChanged] + 105
9 UIKit 0x0033a708 -[UITableView reloadData] + 773
10 UIKit 0x00337844 -[UITableView layoutSubviews] + 42
11 QuartzCore 0x01d6fa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d71ddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d170b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d18294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d1846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00db089b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d456e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d0e1d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d0d840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d0d761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017261c4 GSEventRunModal + 217
22 GraphicsServices 0x01726289 GSEventRun + 115
23 UIKit 0x002cdc93 UIApplicationMain + 1160
24 subview 0x000023b4 main + 102
25 subview 0x00002345 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
谢谢您提前提供帮助
I have problems entering a next view in the TableViewController.
When I click on the cells i see the NSLog-text, but there is no action and no second view.
This means the program enter the methods but does nothing. What is my fault?
I am testing around without getting any solution.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0) {
NSLog(@"Index 0");
AudioViewController *audioviewcontroller = [[AudioViewController alloc] initWithNibName:@"AudioViewController" bundle:nil];
[self.navController pushViewController:audioviewcontroller animated:YES];
[audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==1) {
NSLog(@"Index 1");
DisplayViewController *displayviewcontroller = [[DisplayViewController alloc] initWithNibName:@"DisplayViewController" bundle:nil];
[self.navController pushViewController:displayviewcontroller animated:YES];
[displayviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==2) {
LichtViewController *lichtviewcontroller = [[LichtViewController alloc] initWithNibName:@"LichtViewController" bundle:nil];
[self.navController pushViewController:lichtViewController animated:YES];
[lichtviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
NSLog(@"Index 2");
}
if (indexPath.row==3) {
NSLog(@"Index 3");
ProjektorViewController *projektorviewcontroller = [[ProjektorViewController alloc] initWithNibName:@"ProjektorViewController" bundle:nil];
[self.navController pushViewController:projektorviewcontroller animated:YES];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
[projektorviewcontroller release];
}
}
Moreover I tried this code:
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
[currentView removeFromSuperview];
UIView* audioView= audioviewcontroller.view;
[theWindow addSubview:audioView];
[self.navController pushViewController:audioviewcontroller animated:YES]; [audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
I get no warning but a crash and the debugger console shows:
2011-10-26 10:01:59.344 subview[971:207] -[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880
2011-10-26 10:01:59.346 subview[971:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFTimer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x4b44880'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dcf5a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f23313 objc_exception_throw + 44
2 CoreFoundation 0x00dd10bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00d40966 ___forwarding___ + 966
4 CoreFoundation 0x00d40522 _CF_forwarding_prep_0 + 50
5 UIKit 0x0047a6ff -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 111
6 UIKit 0x0047a3b0 -[UITableViewRowData invalidateAllSections] + 66
7 UIKit 0x00331d23 -[UITableView(_UITableViewPrivate) _updateRowData] + 113
8 UIKit 0x0032d65c -[UITableView noteNumberOfRowsChanged] + 105
9 UIKit 0x0033a708 -[UITableView reloadData] + 773
10 UIKit 0x00337844 -[UITableView layoutSubviews] + 42
11 QuartzCore 0x01d6fa5a -[CALayer layoutSublayers] + 181
12 QuartzCore 0x01d71ddc CALayerLayoutIfNeeded + 220
13 QuartzCore 0x01d170b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
14 QuartzCore 0x01d18294 _ZN2CA11Transaction6commitEv + 292
15 QuartzCore 0x01d1846d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99
16 CoreFoundation 0x00db089b __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
17 CoreFoundation 0x00d456e7 __CFRunLoopDoObservers + 295
18 CoreFoundation 0x00d0e1d7 __CFRunLoopRun + 1575
19 CoreFoundation 0x00d0d840 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x00d0d761 CFRunLoopRunInMode + 97
21 GraphicsServices 0x017261c4 GSEventRunModal + 217
22 GraphicsServices 0x01726289 GSEventRun + 115
23 UIKit 0x002cdc93 UIApplicationMain + 1160
24 subview 0x000023b4 main + 102
25 subview 0x00002345 start + 53
26 ??? 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Thank you for help in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它适合您,请尝试下面的代码,这就是我在 tableView didSelectRowAtIndexPath 中声明对象/变量的方式。在函数顶部声明您的对象(视图)
Try the codes below if it works for you, this is how I declare my objects/variables in the tableView didSelectRowAtIndexPath. Declare your object (views) at the top of the function
与视图控制器关联的导航控制器的代理是 self.navigationController,当您在其上推送视图控制器时,您是否检查过它不为零?
您无法从视图控制器创建导航控制器(请参阅这篇文章 进行解释),您可以找到有关如何使用 UINavigationControllers 此处。
The proxy for the navigation controller associated with the view controller is
self.navigationController
, have you checked that this is not nil when you push a view controller on it?You can't create your navigation controller from the view controller (see this post for an explanation), you can find a tutorial on how to use UINavigationControllers here.
根据您的错误控制台,我认为问题在于部分的数量。如果您提供完整的表格视图代码,那么我认为会发现问题。
according to your error console i think there is problem is number of section.if you give the full tableview code then i think problem will be found.