How to update DetailView using MasterDetail Application Template

后端 未结 1 1064
臣服心动
臣服心动 2020-12-30 08:26

I\'m new to using the split view for creating iPad applications. When I first create the project just using the standard MasterDetail Application template (Xcode 4.2), it c

相关标签:
1条回答
  • 2020-12-30 08:53

    There are a couple different ways you could do it. First off, like you said, remove the pushViewController call (I don't know why Apple's template does this... maybe just to show you you can?).

    Next, let your MasterViewController know about the DetailViewController that is already displayed. I usually set master.detailViewController = detailViewController in the appDelegate.

    Remember, the DetailViewController is already being displayed, so you won't always need to realloc it (unless you are replacing it with some other view)

    First Option

    Use delegate calls to set the information. Declare a protocol to pass information to the detailView and have it display it appropriately. Here is a tutorial describing this in more detail.

    Second Option

    Pass DetailViewController some data & override the setter to refresh the detailView. Here is a tutorial describing this in more detail.

    // in DetailViewController    
    - (void)setDetailItem:(id)newDetailItem {
            if (detailItem != newDetailItem) {
                [detailItem release];
                detailItem = [newDetailItem retain];
    
                // Update the view.
                navigationBar.topItem.title = detailItem;
            NSString * imageName = [NSString stringWithFormat:@"%@.png",detailItem];
            [self.fruitImageView setImage:[UIImage imageNamed:imageName]];
            }
        }
    

    Edit: Just looked at the template again, and setDetailItem type code is already in there, but the code is creating a completely new detailView so the detailView that is viewable on the splitViewController is not changed at all.

    0 讨论(0)
提交回复
热议问题