self.parentViewController 记录 UINavigationController,但表现得像 UIViewController
代码:
- (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
类型转换为a UINavigationController
我从 Xcode
收到以下警告: 不兼容的指针类型用“UIViewController *”类型的表达式初始化“UINavigationController *”
我想我收到警告是因为 Xcode 认为 self.parentViewController
是一个 UIViewController< /代码>。就在那时我决定我需要“类型转换”(我不是 xcode / ios dev)。
类型转换前的堆栈跟踪:
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 通用公共许可证保护,并且您 欢迎更改它和/或在某些情况下分发它的副本 状况。输入“显示复制”以查看条件。有 GDB绝对没有保证。输入“显示保修”以了解详细信息。 该 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 核心基础 0x00d34522 _CF_forwarding_prep_0 + 50 5 UIKit 0x001d22b7 -[UISectionRowData 刷新WithSection:tableView:tableViewRowData:] + 1834 6 UIKit
0x001cfd88 -[UITableViewRowData 行数] + 108 7 UIKit
0x00083677 -[UITableView noteNumberOfRowsChanged] + 132 8 UIKit
0x00090708 -[UITableView 重新加载数据] + 773 9 UIKit
0x0008d844 -[UITableView 布局子视图] + 42 10 QuartzCore
0x016ada5a -[CALayer 布局子层] + 181 11 QuartzCore
0x016afddc CALayerLayoutIfNeeded + 220 12 QuartzCore
0x016550b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 13 石英核 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' 当前语言:自动;目前objective-c (gdb)
我应该如何克服这个问题?
Code:
- (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];
}
This is being called on a UIButton
TouchUpInside
.
NSLog(@"%@", self.parentViewController)
logs a UINavigationController
but without typecasting self.parentViewController
as a UINavigationController
I get the follow warning from Xcode
:Incompatible pointer types initializing 'UINavigationController *' with an expression of type 'UIViewController *'
I assume I get the warning because Xcode thinks self.parentViewController
is a UIViewController
. That's when I decided I need to "type cast" (i'm not to xcode / ios dev).
Strack trace before typecasting:
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)
Stack trace after typecasting:
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 99324. 2011-10-08
14:27:52.593 Do You Like Me[99324:207] -[RegistrationViewController
tableView:numberOfRowsInSection:]: unrecognized selector sent to
instance 0x6833500 2011-10-08 14:27:52.596 Do You Like Me[99324:207]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RegistrationViewController
tableView:numberOfRowsInSection:]: unrecognized selector sent to
instance 0x6833500'
* Call stack at first throw: ( 0 CoreFoundation 0x00dc35a9 exceptionPreprocess + 185 1 libobjc.A.dylib
0x00f17313 objc_exception_throw + 44 2 CoreFoundation
0x00dc50bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3
CoreFoundation 0x00d34966 __forwarding + 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 GraphicsServices
0x00ffb1c4 GSEventRunModal + 217 21 GraphicsServices
0x00ffb289 GSEventRun + 115 22 UIKit
0x00023c93 UIApplicationMain + 1160 23 Do You Like Me
0x00001fde main + 126 24 Do You Like Me
0x00001f55 start + 53 ) terminate called after throwing an instance of
'NSException' Current language: auto; currently objective-c (gdb)
How should I go about getting past this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
三件事。首先,使用
navigationController
属性而不是parentViewController
。因此,不要这样做: 这样做:
其次,不要向导航控制器发送
release
消息:第三,控制台中的错误消息强烈提示问题的本质:
这意味着程序在尝试将消息
tableView:numberOfRowsInSection:
发送到RegistrationViewController
的实例时崩溃,因此请确保该类具有缺少的方法的实现。 (注意:如果您认为它已经实现了该方法,请仔细检查以确保其拼写正确。)Three things. First, use the
navigationController
property instead ofparentViewController
. So instead of this:do this:
Second, don't send a
release
message to the navigation controller:Third, the error message in the console gives a strong hint as to the nature of the problem:
This means that the program crashed trying to send the message
tableView:numberOfRowsInSection:
to an instance ofRegistrationViewController
, so make sure that class has an implementation of the missing method. (Note: if you think it already does implement that method, double-check to make sure it's spelled correctly.)