我正在构建一个标签栏应用程序,其中有三个选项卡,每个选项卡将一个不同的.plist加载到一个向下钻取的表视图中。我终于能够设置它,以便至少显示第一级,但是如果您尝试选择其中一个,我的应用程序会崩溃。我不确定它是否是我在界面构建器中链接的方式(稍后),但是有一个明显的问题。
我在我的app委托中唯一建立的是导航控制器来管理我的视图。我使用标签栏模板,因此已经创建了。我将第一个视图的模式更改为导航控制器。我将它创建为IBOutlet,因此我可以将Navigation控制器链接到我在App Delegate中创建的正确变量。
这是我的第一个视图的初始化代码:
@interface IndustryTableView : UITableViewController {
NSDictionary *industryData;
NSArray *tableDataSource;
NSString *CurrentTitle;
NSInteger CurrentLevel;
}
@property (nonatomic, retain) NSDictionary *industryData;
@property (nonatomic, retain) NSArray *tableDataSource;
@property (nonatomic, retain) NSString *CurrentTitle;
@property (nonatomic, readwrite) NSInteger CurrentLevel;
@end
我的文件被导入到实现中。以下是该
的相关代码 - (void)viewDidLoad {
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"IndustryData.plist"];
NSDictionary *tempDict = [[NSDictionary alloc] initWithContentsOfFile:DataPath];
self.industryData = tempDict;
[tempDict release];
if(CurrentLevel == 0) {
NSArray *tempArray = [[NSArray alloc] init];
self.tableDataSource = tempArray;
[tempArray release];
self.tableDataSource = [self.industryData objectForKey:@"Rows"];
self.navigationItem.title = @"Back";
}
else
self.navigationItem.title = CurrentTitle;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Get the dictionary of the selected data source.
NSDictionary *dictionary = [self.tableDataSource objectAtIndex:indexPath.row];
//Get the children of the present item.
NSArray *Children = [dictionary objectForKey:@"Children"];
Jqt62m7AppDelegate *AppDelegate = (Jqt62m7AppDelegate *) [[UIApplication sharedApplication] delegate];
if([Children count] == 0) {
DetailView *dvController = [[DetailView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
[AppDelegate.indNavControl pushViewController:dvController animated:YES];
[dvController release];
}
else {
//Prepare to tableview.
IndustryTableView *indViewControl = [[IndustryTableView alloc] initWithNibName:@"IndustryView" bundle:[NSBundle mainBundle]];
//Increment the Current View
indViewControl.CurrentLevel += 1;
//Set the title;
indViewControl.CurrentTitle = [dictionary objectForKey:@"Title"];
//Push the new table view on the stack
[AppDelegate.indNavControl pushViewController:indViewControl animated:YES];
indViewControl.tableDataSource = Children;
[indViewControl release];
}
}
崩溃错误是程序收到SIGABRT,这是一个非常常见的问题。它出现在[AppDelegate.indNavControl pushViewController:indviewControl animated:YES]行中;如果这有助于任何人,这是调试代码:
(
0 CoreFoundation 0x00dc25a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f16313 objc_exception_throw + 44
2 CoreFoundation 0x00d7aef8 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d7ae6a +[NSException raise:format:] + 58
4 UIKit 0x0020f0fa -[UINib instantiateWithOwner:options:] + 2024
5 UIKit 0x00210ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
6 UIKit 0x000c6628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
7 UIKit 0x000c4134 -[UIViewController loadView] + 120
8 UIKit 0x0021ddd8 -[UITableViewController loadView] + 80
9 UIKit 0x000c400e -[UIViewController view] + 56
10 UIKit 0x000c2482 -[UIViewController contentScrollView] + 42
11 UIKit 0x000d2f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
12 UIKit 0x000d1555 -[UINavigationController _layoutViewController:] + 43
13 UIKit 0x000d27aa -[UINavigationController _startTransition:fromViewController:toViewController:] + 326
14 UIKit 0x000cd32a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
15 UIKit 0x000d4562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
16 UIKit 0x000cd1c4 -[UINavigationController pushViewController:animated:] + 62
17 Jqt62m7 0x00002a78 -[IndustryTableView tableView:didSelectRowAtIndexPath:] + 952
18 UIKit 0x0008bb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
19 UIKit 0x00081b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
20 Foundation 0x0079b79e __NSFireDelayedPerform + 441
21 CoreFoundation 0x00da38c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
22 CoreFoundation 0x00da4e74 __CFRunLoopDoTimer + 1220
23 CoreFoundation 0x00d012c9 __CFRunLoopRun + 1817
24 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
25 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
26 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
27 GraphicsServices 0x00ffa289 GSEventRun + 115
28 UIKit 0x00022c93 UIApplicationMain + 1160
29 Jqt62m7 0x00001cc9 main + 121
30 Jqt62m7 0x00001c45 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
(gdb)
所以这对我来说还有很长的路要走 - 为什么我的程序会崩溃?
答案 0 :(得分:1)
我认为问题在于你推动视图控制器的方式。这一行:
[AppDelegate.indNavControl pushViewController:dvController animated:YES];
似乎不对我说,虽然我承认我不知道AppDelegate.indNavControl
是什么。你应该做这样的事情:
[self.navigationController pushViewController:dvController animated:YES];
答案 1 :(得分:1)
当用户在表格视图单元格中选择一行时,似乎会引发异常。这是因为您正在使用笔尖名称IndustryTableView
创建IndustryView
的实例。尝试更改此行代码:
IndustryTableView *indViewControl = [[IndustryTableView alloc] initWithNibName:@"IndustryView" bundle:[NSBundle mainBundle]];
对此:
IndustryTableView *indViewControl = [[IndustryTableView alloc] initWithNibName:@"IndustryTableView" bundle:[NSBundle mainBundle]];
请注意,在大多数情况下,为包提供nil
并没有什么区别,通常应该暗示主包。虽然您没有提供整个堆栈跟踪,但显然在-loadView
上调用IndustryTableView
并且它尝试从错误的笔尖加载时出现问题。