\"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" />
开发者

pushViewController failing

开发者 https://www.devze.com 2023-04-10 07:32 出处:网络
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

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:@"Detai开发者_如何学JAVAlView" 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


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:

Could not load NIB in bundle: 'NSBundle </.../Teste Data Nav.app> (loaded)' with name 'DetailView'

which means that there is no .xib file in your bundle called DetailView. Make sure that you use the correct name of the file:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    ItemDetailsView *detailViewController = [[ItemDetailsView alloc] initWithNibName:@"ItemDetailsView" bundle:nil];

    // ERROR HERE
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release]; 
}

Edit (from comments) connect the view to the File's Owner like so:

pushViewController failing


Make sure that self has a navigationController parent. If this is the main view that appears when the app starts up, you need to add a UINavigationController to the MainWindow.xib and set its rootViewController to the view controller with this table.

You can test this out by doing:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    NSLog("self.navController view controllers: %@", [[[self navigationController] viewControllers] description]);
    // Or something like this:
    if (self.parentViewController == self.navigationController) {
        NSLog(@"I have a nav controller dad!");
    } else {
        NSLog(@"I have no nav controller!");
    }
    // ItemDetailsView *detailViewController = [[ItemDetailsView alloc] initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]];
    // ERROR HERE
    // [self.navigationController pushViewController:detailViewController animated:YES];
    // [detailViewController release]; 
}

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 your self does not have a navigationController parent.


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 ...

0

精彩评论

暂无评论...
验证码 换一张
取 消