PushViewController 失败
我正在尝试做一个“项目列表”-> “项目详细信息”是一种应用程序。 到目前为止,我已经成功地完成了列表部分。我还为项目详细信息创建了一个新视图,但是当我单击我想查看详细信息的项目时,出现错误。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ItemDetailsView *detailViewController = [[ItemDetailsView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
// ERROR HERE
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
到目前为止,新视图只有一个空标签,上面写着“视图已更改:确定”。没有别的了。
ItemDetailsView 是一个继承自 UIViewController 的视图。
为了创建这个视图,我转到“新建文件”->“可可触摸 -> UIViewController 子类。
当我尝试执行下面的行 //ERROR HERE
以下是完整消息时,我收到的错误是“signabrt”:
2011-10-02 17:26:03.582 Teste Data Nav[10035:b303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/leo/Library/Application Support/iPhone Simulator/4.3.2/Applications/FA60D1E7-1B98-4943-98AA-C86A2339AC3E/Teste Data Nav.app> (loaded)' with name 'DetailView''
*** Call stack at first throw:
(
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 0x000c400e -[UIViewController view] + 56
9 UIKit 0x000c2482 -[UIViewController contentScrollView] + 42
10 UIKit 0x000d2f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x000d1555 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x000d27aa -[UINavigationController _startTransition:fromViewController:toViewController:] + 326
13 UIKit 0x000cd32a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x000d4562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
15 UIKit 0x000cd1c4 -[UINavigationController pushViewController:animated:] + 62
16 Teste Data Nav 0x00002d4c -[RootViewController tableView:didSelectRowAtIndexPath:] + 220
17 UIKit 0x0008bb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
18 UIKit 0x00081b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
19 Foundation 0x0079b79e __NSFireDelayedPerform + 441
20 CoreFoundation 0x00da38c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
21 CoreFoundation 0x00da4e74 __CFRunLoopDoTimer + 1220
22 CoreFoundation 0x00d012c9 __CFRunLoopRun + 1817
23 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
24 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
25 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
26 GraphicsServices 0x00ffa289 GSEventRun + 115
27 UIKit 0x00022c93 UIApplicationMain + 1160
28 Teste Data Nav 0x000023b9 main + 121
29 Teste Data Nav 0x00002335 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
I am trying to do a "list of items" -> "item details" kind of an application.
I've managed to do the list part just fine so far. I've also created a new view for the item detail but here I get a error when I click the item I want to see the details.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ItemDetailsView *detailViewController = [[ItemDetailsView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
// ERROR HERE
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
So far the new view only have a empty label that says "View Changed: OK". Nothing else.
ItemDetailsView is a view that inherits from UIViewController.
To create this view I went to New File -> Cocoa Touch -> UIViewController subclass.
The error I'm getting is a "signabrt" when I try to execute the line below //ERROR HERE
Here follows the complete message:
2011-10-02 17:26:03.582 Teste Data Nav[10035:b303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/leo/Library/Application Support/iPhone Simulator/4.3.2/Applications/FA60D1E7-1B98-4943-98AA-C86A2339AC3E/Teste Data Nav.app> (loaded)' with name 'DetailView''
*** Call stack at first throw:
(
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 0x000c400e -[UIViewController view] + 56
9 UIKit 0x000c2482 -[UIViewController contentScrollView] + 42
10 UIKit 0x000d2f25 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48
11 UIKit 0x000d1555 -[UINavigationController _layoutViewController:] + 43
12 UIKit 0x000d27aa -[UINavigationController _startTransition:fromViewController:toViewController:] + 326
13 UIKit 0x000cd32a -[UINavigationController _startDeferredTransitionIfNeeded] + 266
14 UIKit 0x000d4562 -[UINavigationController pushViewController:transition:forceImmediate:] + 932
15 UIKit 0x000cd1c4 -[UINavigationController pushViewController:animated:] + 62
16 Teste Data Nav 0x00002d4c -[RootViewController tableView:didSelectRowAtIndexPath:] + 220
17 UIKit 0x0008bb68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
18 UIKit 0x00081b05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
19 Foundation 0x0079b79e __NSFireDelayedPerform + 441
20 CoreFoundation 0x00da38c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
21 CoreFoundation 0x00da4e74 __CFRunLoopDoTimer + 1220
22 CoreFoundation 0x00d012c9 __CFRunLoopRun + 1817
23 CoreFoundation 0x00d00840 CFRunLoopRunSpecific + 208
24 CoreFoundation 0x00d00761 CFRunLoopRunInMode + 97
25 GraphicsServices 0x00ffa1c4 GSEventRunModal + 217
26 GraphicsServices 0x00ffa289 GSEventRun + 115
27 UIKit 0x00022c93 UIApplicationMain + 1160
28 Teste Data Nav 0x000023b9 main + 121
29 Teste Data Nav 0x00002335 start + 53
)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基本上,它找不到名为“DetailView”的 .xib 文件。确保您的
initWithNibName:
具有.xib
文件的正确字符串名称。该错误的重要部分是:
这意味着您的包中没有名为
DetailView
的 .xib 文件。确保使用正确的文件名:编辑(根据注释)将视图连接到
文件所有者
,如下所示:确保
self
有一个navigationController
父级。如果这是应用程序启动时出现的主视图,则需要将 UINavigationController 添加到MainWindow.xib
中,并将其 rootViewController 设置为具有此表的视图控制器。您可以通过执行以下操作来测试这一点:
如果 NSLog 打印出视图控制器数组,则存在另一个问题,但如果它在
NSLog
上抛出错误或打印出空数组,则您的self
没有navigationController
父级。Basically, it cannot find a .xib file called "DetailView". Make sure that your
initWithNibName:
has the correct string name for the.xib
file.The important part of that error is:
which means that there is no .xib file in your bundle called
DetailView
. Make sure that you use the correct name of the file:Edit (from comments) connect the view to the
File's Owner
like so:Make sure that
self
has anavigationController
parent. If this is the main view that appears when the app starts up, you need to add a UINavigationController to theMainWindow.xib
and set its rootViewController to the view controller with this table.You can test this out by doing:
If the NSLog prints out an array of view controllers, then there is another problem, but if it throws an error on the
NSLog
or it prints out an empty array, then yourself
does not have anavigationController
parent.不确定是否是同一个问题,但我遇到了一个问题,即使用 sigabort 推送视图会导致崩溃。
就我而言,我在启动详细视图时的 Xib 名称中有一个拼写错误。如果由于某种原因 Xib 的结构不完善,它也可能导致同样的问题。在这两种情况下,它都会返回一个非零对象,并且在您尝试推送它之前它不会爆炸。
这是我关于如何更早检测到它的问题:
更早检测有问题的 XIB 视图
测试时,您还可以尝试创建一些其他简单的视图并推送它。如果有效,那么您已将问题范围缩小到推送中的拼写错误、视图名称中的拼写错误或格式不正确的 XIB 文件。
希望这有助于您走上正轨......
Not sure if it's the same issue but I had an issue where pushing a view was blowing up with a sigabort.
In my case I had a typo in the name of Xib I was initing the detail view with. It can also cause the same issue if for some reason the Xib isn't well formed. In both cases, it will return you a non nil object and it doesn't blow up until you try and push it.
Here was my question on how to detect it earlier:
Detecting problematic XIB views earlier
As a test, you can also try to create some other trivial view and push that. If that works then you've narrowed the problem down to a typo in the push, a typo in the name of the view or a non-well formed XIB file.
Hope that helps get you on the right track ...