开发者

A couple of problems customizing Apples MultipleDetailViews Example

开发者 https://www.devze.com 2023-02-26 02:55 出处:网络
I have been trying to add/implement this example to my existing Split View app tests. Apple Example I what to use the concept of replacing the detail view or right view, otherwise my app will be dif

I have been trying to add/implement this example to my existing Split View app tests.

Apple Example

I what to use the concept of replacing the detail view or right view, otherwise my app will be different. It is this difference that is causing my problems.

I have a rootviewcontroller or left view and upon choosing something here a new view is pushed onto this view. Upon choosing something in this "pushed view" I want to change the detail view or right hand view. This is the difference to apples example where the rootview does not have a pushed view on it and thus references are not broken.

Below is my change code - the new View DVCases is being initialized but the didload is not happening.

The issues are learner issues to do with my classes.

  1. This below code is in my RootViewController implementation code but my reference to splitviewcontroller is not working if there is a new view pushed.

  2. Second self.navigationcontroller is not correct because I have pushed a second view to the rootviewcontroller.

To centralize and simplify the code what I have done is from the delegate of the pushed view in the didselect event i call a method found in the rootviewcontroller passing the index as a parameter. The code for my custom method contains what is below.

So my question is how do I do this in my situation where I have pushed other views onto the rootview or left side. It appears that after pushing a view the reference to splitviewcontroller is gone and self.navigationcontroller is also gone/or wrong.

UIViewController <SubstitutableDetailViewController> *detailViewController = nil;

if (value == 0) {
    DVCases *newDetailViewController = [[DVCases alloc] initWithNibName:@"DVCases" bundle:nil];
    detailViewController = newDetailViewController;
}

// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
splitViewController.viewControllers = viewControllers;
[viewControllers release];

// Dismiss the popover if it's present.
if (popoverController != nil) {
    [popoverController dismissPopoverAnimated:YES];
}

// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (roo开发者_JS百科tPopoverButtonItem != nil) {
    [detailViewController showRootPopoverButtonItem:self.rootPopoverButtonItem];
}

[detailViewController release];

I would appreciate any tips or help you might have.


Initialization of any viewcontroller class does not mean that it will make call to viewDidLoad method.

viewDidLoad method will only be called when you load view of that viewController. Generally we do it either by following methods.

1. Pushing it on navigation stack.
2. Presenting it using modal transition.
3. Adding it on some other view using [someView addSubView:controller.view];
4. Selecting any tabBar item for the first time Or tapping tabBar Item twice.
there may be some other scenarios.

But right now in your code I don't see any of this element.

Initialization means you are calling the direct method for intialization(calling its constructor) like here in above code initWithNibName will call this method of DVClass not any other(until this method had call for other methods inside it).

Thanks


As I am learning to properly code - my problems centres around that.

The above code is perfect as long as you call it using the same instance. I was not. Thus it was not working.

In the end I made my RootViewController a delegate for a method that has the above code. Thus when in another view - this view can call this method and the proper or real instance of RootViewController will implement it.

0

精彩评论

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