Objective c UITableView-点击单元格并获取下一个视图
在TableViewController中输入下一个视图时遇到问题。 当我点击单元格时,我会看到NSLog文本,但没有操作,也没有第二视图。 这意味着程序输入方法,但不执行任何操作。什么是我的错? 我正在四处测试,没有得到任何解决方案Objective c UITableView-点击单元格并获取下一个视图,objective-c,uitableview,pushviewcontroller,Objective C,Uitableview,Pushviewcontroller,在TableViewController中输入下一个视图时遇到问题。 当我点击单元格时,我会看到NSLog文本,但没有操作,也没有第二视图。 这意味着程序输入方法,但不执行任何操作。什么是我的错? 我正在四处测试,没有得到任何解决方案 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row==0) { N
- (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'
提前感谢您的帮助与视图控制器关联的导航控制器的代理是
self.navigationController
,当您将视图控制器推到其上时,是否检查该代理是否为零
您无法从视图控制器创建导航控制器(有关说明,请参阅),您可以找到有关如何使用UINavigationController的教程。请尝试下面的代码如果适用,这就是我在tableView DidSelectRowatineXpath中声明对象/变量的方式。在函数顶部声明对象(视图)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
AudioViewController *audioviewcontroller = [[AudioViewController alloc] initWithNibName:@"AudioViewController" bundle:nil];
DisplayViewController *displayviewcontroller = [[DisplayViewController alloc] initWithNibName:@"DisplayViewController" bundle:nil];
LichtViewController *lichtviewcontroller = [[LichtViewController alloc] initWithNibName:@"LichtViewController" bundle:nil];
ProjektorViewController *projektorviewcontroller = [[ProjektorViewController alloc] initWithNibName:@"ProjektorViewController" bundle:nil];
if (indexPath.row==0) {
NSLog(@"Index 0");
[self.navController pushViewController:audioviewcontroller animated:YES];
[audioviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==1) {
NSLog(@"Index 1");
[self.navController pushViewController:displayviewcontroller animated:YES];
[displayviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
}
if (indexPath.row==2) {
[self.navController pushViewController:lichtViewController animated:YES];
[lichtviewcontroller release];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
NSLog(@"Index 2");
}
if (indexPath.row==3) {
NSLog(@"Index 3");
[self.navController pushViewController:projektorviewcontroller animated:YES];
[tableView deselectRowAtIndexPath: indexPath animated:YES];
[projektorviewcontroller release];
}
}
根据您的错误控制台,我认为问题在于节数。如果您提供完整的tableview代码,我认为问题会被发现。我现在就去检查它。谢谢,我是headerfile中的navigationController。navigationController需要什么样的值?我测试了它,但效果是一样的。细胞会发光或熄灭,但没有任何作用。你试过从self.navController切换到self.navionController吗?非常感谢,那是我的错。UiViewController有一个属性navigationController,但我自己创建了一个navController,这导致了我的问题:)