objective-c - 为什么我的向下钻取应用程序崩溃了?

标签 objective-c ios xcode

我正在构建一个选项卡栏应用程序,其中包含三个选项卡,每个选项卡将不同的 .plist 加载到下钻 TableView 中。我终于能够对其进行设置,以便至少显示第一级,但如果您尝试选择其中一个,我的应用程序就会崩溃。我不确定这是否是我在 Interface Builder 中链接的方式(稍后会详细介绍),但有一个明显的问题。

我在我的应用委托(delegate)中构建的唯一东西是一个导航 Controller 来管理我的 View 。我使用标签栏模板,所以它已经创建好了。我将第一个 View 的模式更改为导航 Controller 。我将其创建为 IBOutlet,这样我就可以将导航 Controller 链接到我在 App Delegate 中创建的适当变量。

这是我的第一个 View 的初始化代码:

@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) 

所以我问了很长的路 - 为什么我的程序崩溃了?

最佳答案

似乎是当用户在表格 View 单元格中选择一行时导致异常。这是因为您正在使用 IndustryView 的 nib 名称创建 IndustryTableView 的实例。尝试更改这行代码:

IndustryTableView *indViewControl = [[IndustryTableView alloc] initWithNibName:@"IndustryView" bundle:[NSBundle mainBundle]];

对此:

IndustryTableView *indViewControl = [[IndustryTableView alloc] initWithNibName:@"IndustryTableView" bundle:[NSBundle mainBundle]];

请注意,在大多数情况下,为 bundle 提供 nil 并没有什么区别,通常应该这样做以暗示 主 bundle 。虽然您没有提供整个堆栈跟踪,但很明显,当 -loadView 在您的 IndustryTableView 上调用时,问题就出现了,它会尝试从错误的位置加载 Nib 。

关于objective-c - 为什么我的向下钻取应用程序崩溃了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7085672/

相关文章:

ios - 获取信息 JSON Google 图书 - IOS

ios - -[__NSArrayM insertObject :atIndex:]: object cannot be nil when calling addChildBehavior:

ios - TableViewCell 更改框架中的删除按钮

objective-c - NSMutableArray removeObject中的奇怪错误

ios - 无法使卡片翻转动画起作用

ios - 使用自定义选项卡栏 Controller 类在两个 View Controller 之间传递数据

ios - 在 Swift 中将 unicode 标量表情符号转换为字符串

objective-c - 以编程方式调整 NSSplitView 的大小

ios - View 无法正确显示 Storyboard

iphone - 将其存储在手机内存中 - 这可能吗?苹果?