代码:
- (IBAction)continueTouchHandler:(id)sender {
RegistrationViewController *registration = [[RegistrationViewController alloc] initWithNibName:@"RegistrationView" bundle:nil];
UINavigationController *navController = (UINavigationController *)self.parentViewController;
[navController pushViewController:registration animated:YES];
[navController release];
[registration release];
}
这是在UIButton
TouchUpInside
上调用的。
NSLog(@"%@", self.parentViewController)
记录一个UINavigationController
但没有将self.parentViewController
作为UINavigationController
进行类型转换我从Xcode
收到以下警告:
Incompatible pointer types initializing 'UINavigationController *' with an expression of type 'UIViewController *'
我认为我收到了警告,因为Xcode认为self.parentViewController
是UIViewController
。那时我决定需要“输入”(我不是xcode / ios dev)。
在类型转换前进行Strack跟踪:
GNU gdb 6.3.50-20050815 (Apple version gdb-1518) (Sat Feb 12 02:52:12 UTC 2011)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all
Attaching to process 99533.
Current language: auto; currently objective-c
(gdb)
类型转换后的堆栈跟踪:
GNU gdb 6.3.50-20050815(Apple版gdb-1518)(2月12日星期二02:52:12 UTC 2011)版权所有2004 Free Software Foundation,Inc。GDB是免费的 GNU通用公共许可证涵盖的软件,您就是 欢迎更改和/或在某些情况下分发它的副本 条件。输入“show copying”查看条件。有 绝对不保证GDB。输入“show warranty”了解详情。 此GDB配置为“x86_64-apple-darwin”.sharedlibrary apply-load-rules all附加到进程99324. 2011-10-08 14:27:52.593你喜欢我吗[99324:207] - [RegistrationViewController tableView:numberOfRowsInSection:]:发送到的无法识别的选择器 实例0x6833500 2011-10-08 14:27:52.596你喜欢我吗[99324:207] *由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [RegistrationViewController tableView:numberOfRowsInSection:]:发送到的无法识别的选择器 实例0x6833500' * 首次调用堆栈:(0 CoreFoundation 0x00dc35a9 exceptionPreprocess + 185 1 libobjc.A.dylib
0x00f17313 objc_exception_throw + 44 2 CoreFoundation
0x00dc50bb - [NSObject(NSObject)doesNotRecognizeSelector:] + 187 3
CoreFoundation 0x00d34966 __ 转发 + 966 4 CoreFoundation 0x00d34522 _CF_forwarding_prep_0 + 50 5 UIKit 0x001d22b7 - [UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 1834 6 UIKit
0x001cfd88 - [UITableViewRowData numberOfRows] + 108 7 UIKit
0x00083677 - [UITableView noteNumberOfRowsChanged] + 132 8 UIKit
0x00090708 - [UITableView reloadData] + 773 9 UIKit
0x0008d844 - [UITableView layoutSubviews] + 42 10 QuartzCore
0x016ada5a - [CALayer layoutSublayers] + 181 11 QuartzCore
0x016afddc CALayerLayoutIfNeeded + 220 12 QuartzCore
0x016550b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 13 QuartzCore 0x01656294 _ZN2CA11Transaction6commitEv + 292 14 QuartzCore 0x0165646d _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 15 CoreFoundation 0x00da489b CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 27 16 CoreFoundation 0x00d396e7 __CFRunLoopDoObservers + 295 17 CoreFoundation 0x00d021d7 __CFRunLoopRun + 1575 18 CoreFoundation 0x00d01840 CFRunLoopRunSpecific + 208 19 CoreFoundation
0x00d01761 CFRunLoopRunInMode + 97 20图形服务
0x00ffb1c4 GSEventRunModal + 217 21图形服务
0x00ffb289 GSEventRun + 115 22 UIKit
0x00023c93 UIApplicationMain + 1160 23你喜欢我吗? 0x00001fde main + 126 24你喜欢我吗? 0x00001f55 start + 53)在抛出一个实例后终止调用 'NSException'当前语言:auto;目前objective-c(gdb)
我该如何解决这个问题?
答案 0 :(得分:3)
三件事。首先,使用navigationController
属性而不是parentViewController
。所以不要这样:
UINavigationController *navController = (UINavigationController *)self.parentViewController;
[navController pushViewController:registration animated:YES];
这样做:
[self.navigationController pushViewController:registration animated:YES];
其次,不要向导航控制器发送release
消息:
[navController release]; // Don't do this!
第三,控制台中的错误消息强烈暗示问题的性质:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[RegistrationViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6833500
这意味着程序崩溃尝试将消息tableView:numberOfRowsInSection:
发送到RegistrationViewController
的实例,因此请确保该类具有缺少方法的实现。 (注意:如果您认为它已经实现了该方法,请仔细检查以确保拼写正确。)