gpt4 book ai didi

ios - self.parentViewController 记录 UINavigationController,但表现得像 UIViewController

转载 作者:行者123 更新时间:2023-11-28 20:42:52 25 4
gpt4 key购买 nike

代码:

- (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 收到以下警告:使用“UIViewController *”类型的表达式初始化“UINavigationController *”的不兼容指针类型

我假设我收到警告是因为 Xcode 认为 self.parentViewControllerUIViewController。那时我决定我需要“类型转换”(我不是 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 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)

我应该如何克服这个问题?

最佳答案

三件事。首先,使用 navigationController 属性代替 parentViewController。所以不是这个:

UINavigationController *navController = (UINavigationController *)self.parentViewController;  
[navController pushViewController:registration animated:YES];

这样做:

[self.navigationController pushViewController:registration animated:YES];

其次,不要向导航 Controller 发送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 的实例时崩溃,因此请确保该类具有缺失方法的实现. (注意:如果您认为它已经实现了该方法,请仔细检查以确保拼写正确。)

关于ios - self.parentViewController 记录 UINavigationController,但表现得像 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7699668/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com