开发者

Still having difficulty swapping between views properly

I have an app that uses a number of views, and it was getting pretty awkward swapping between them so I thought it might be an idea to make some code that would automatically go to a numbered page, load the appropriate view, then perform any setup that needed doing based upon that view. I came up with the following. The test page I've set up it swaps to OK and even sets the delegate properly, but it just won't perform any setup operations on the contents of the page, such as changing the text on the labels it contains or flicking the toggle switch to ON. I've been through the program step by step and all of the commands are being executed, but the results just don't show up on the final screen.

currentMenu is a UIViewController pointer that I aim at the current ViewController in use so that I know what to dismiss later. clusterMenu is a specific view controller of type ClusterMenu that I am using as a sample page to switch to.

It also occurs to me that the resources might not release properly with this code, but that's something I can deal with later once I can work out why it's not being set up correctly in the first place.

Here is the code:

UIViewController *vanishing = currentMenu;

if (page == 3){
    clusterMenu = [[ClusterMenu alloc] initWithHeader:clusterMap.header];
    [clusterMenu setDelegate:self];
    clusterMenu.editSwitch.on = 开发者_运维百科clusterMap.editMode;
    [clusterMenu changeEditStatus];
    currentMenu = clusterMenu;
}

[UIView transitionFromView:vanishing.view toView:currentMenu.view duration:0.5 
                options:UIViewAnimationOptionTransitionCurlUp 
                completion:^(BOOL done){[vanishing release];}];


Good question. Given the limited code that was posted, it's tough for me to guide you on specific changes. Instead, I'd recommend having a look at an Apple sample projet (link below) that should help you on your way. You can probably use the Apple architecture and simply shoehorn in your view controllers to get the page swapping behaviour.

http://developer.apple.com/iphone/library/samplecode/PageControl/Introduction/Intro.html

I hope this helps. Sorry I couldn't give you a one-line fix. Andrew


Put your initialization commands in the view's init method, and wait for it to get called. Don't halt, as this will prevent the views from getting loaded, just exit your current method instead.

In Cocoa, you don't tell the OS what to do, you wait for it to tell you.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜