简体   繁体   中英

iOS Development: Crash when loading a UITableViewController and there's no error in the console

I've spent that last two hours starring at the most cookie cutter block of code and I can't figure out why it's crashing, plus there's no error message or any useful data shown in the console or debugger. I'm simply trying to load a view controller that inherits from UITableViewController and its only instance var is a UITableView object. Here's the class code...

@interface PlayFriendViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource>
{
 IBOutlet UITableView *rootTableView;
}

@property (nonatomic, retain) IBOutlet UITableView *rootTableView;

@end

Here's the code that loads it and pushes it on to the stack....

 PlayFriendViewController *pfvc = [[PlayFriendViewController alloc] initWithNibName:@"PlayFriendView_iPhone" bundle:nil];
 [self.navigationController pushViewController:pfvc animated:YES]; //<--Crashes here
 [pfvc release];

and here's the relevant part of the callstack....

0   libSystem.B.dylib              0x33bd52d4 __kill + 8
1   libSystem.B.dylib              0x33bd52c4 kill + 4
2   libSystem.B.dylib              0x33bd52b6 raise + 10
3   libSystem.B.dylib              0x33be9d72 abort + 50
4   libstdc++.6.dylib              0x31bdba20 __gnu_cxx::__verbose_terminate_handler() + 376
5   libobjc.A.dylib                0x3347c594 _objc_terminate + 104
6   libstdc++.6.dylib              0x31bd9df2 __cxxabiv1::__terminate(void (*)()) + 46
7   libstdc++.6.dylib              0x31bd9e46 std::terminate() + 10
8   libstdc++.6.dylib              0x31bd9f16 __cxa_throw + 78
9   libobjc.A.dylib                0x3347b4c4 objc_exception_throw + 64
10  CoreFoundation                 0x33ac07c2 +[NSException raise:format:arguments:] + 62
11  CoreFoundation                 0x33ac07fc +[NSException raise:format:] + 28
12  UIKit                          0x320e4118 -[UITableViewController loadView] + 188
13  UIKit                          0x320a0220 -[UIViewController view] + 24
14  UIKit                          0x320acd04 -[UIViewController contentScrollView] + 16
15  UIKit                          0x320acb74 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 24
16  UIKit                          0x320aca72 -[UINavigationController _layoutViewController:] + 18
17  UIKit                          0x320ac54a -[UINavigationController _startTransition:fromViewController:toViewController:] + 374
18  UIKit                          0x320ac358 -[UINavigationController _startDeferredTransitionIfNeeded] + 176
19  UIKit                          0x320a00be -[UINavigationController pushViewController:transition:forceImmediate:] + 634
20  UIKit                          0x3209fe34 -[UINavigationController pushViewController:animated:] + 28

One thing to note: When I remove the UITableView instance var and all connections to it, the view loads successfully. There's nothing in the view, but at least it doesn't crash.

Any ideas what's happening or how I can get further information on this crash?

Thanks so much for your wisdom!

您在@合成rootTableView吗?

The failure occurs when the new viewController is attempting to load the view, which implies that there's some kind of problem with the .xib or, more likely, connections to the .xib.

I would guess that your UITableView in the .xib is pointing to an invalid delegate or dataSource, or even more likely, the outlet is pointing to something that doesn't exist. Perhaps you changed the name of the tableView outlet or of the viewController .

应该有一个异常记录到控制台,但是如果某种原因无法达到,请尝试将崩溃行放入@try {} @catch () {}块中,打印该异常,然后终止(或不终止)。

Fixed the problem and, like all really puzzling bugs, it was stupid. I guess I don't feel so bad since no one else caught it either, but my view controller should be a subclass of UIViewController , not UITableViewController , since a UITableView object is an instance var of my class and my view controller adheres to the appropriate protocols. Anyhow, fixed it, now it works. That stupid mistake only took me two hours to fix...ugghh.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM