2011-08-11 43 views
1

我正在學習如何在Xcode中編寫應用程序。我正在用一本書來指導我。不幸的是,這本書是用Xcode 3編寫的指南編寫的,我使用的是Xcode 4.這個簡單的視圖切換項目爲什麼不能工作?

現在到目前爲止沒有任何問題,但是這個項目不起作用,而且我根本就不明白,因爲它看起來很有意義。

該項目的目標是使用視圖控制器在三個視圖之間切換。

任何人都可以請看一下,看看我做錯了什麼?

這裏是整個項目:http://www.2shared.com/file/CKO6ACzg/MultipleViews.html

PS:我知道,因爲它是現在的意見,將在頂過對方,這視圖,當你點擊一個新的按鈕沒有被清除堆積。

回答

0

MultipleViewsViewController.h應該是:

#import <UIKit/UIKit.h> 

@class FirstViewController; 
@class SecondViewController; 
@class ThirdViewController; 

@interface MultipleViewsViewController : UIViewController { 


    IBOutlet FirstViewController *firstViewController; 
    IBOutlet SecondViewController *secondViewController; 
    IBOutlet ThirdViewController *thirdViewController; 

} 

//@property (nonatomic, retain) FirstViewController *firstViewController; 
//@property (nonatomic, retain) SecondViewController *secondViewController; 
//@property (nonatomic, retain) ThirdViewController *thirdViewController; 

-(IBAction)loadFirstView:(id)sender; 
-(IBAction)loadSecondView:(id)sender; 
-(IBAction)loadThirdView:(id)sender; 

@end 

MultipleViewsViewController.m應該是:

#import "MultipleViewsViewController.h" 

#import "FirstViewController.h" 
#import "SecondViewController.h" 
#import "ThirdViewController.h" 

@implementation MultipleViewsViewController 

//@synthesize firstViewController; 
//@synthesize secondViewController; 
//@synthesize thirdViewController; 

-(IBAction)loadFirstView:(id)sender{ 
    [secondViewController.view removeFromSuperview]; 
    [thirdViewController.view removeFromSuperview]; 

    [self.view insertSubview:firstViewController.view atIndex:0]; 

} 

-(IBAction)loadSecondView:(id)sender{ 
    [firstViewController.view removeFromSuperview]; 
    [thirdViewController.view removeFromSuperview]; 
    [self.view insertSubview:secondViewController.view atIndex:0]; 

} 

-(IBAction)loadThirdView:(id)sender{ 
    [firstViewController.view removeFromSuperview]; 
    [secondViewController.view removeFromSuperview]; 
    [self.view insertSubview:thirdViewController.view atIndex:0]; 

} 

-(void)dealloc{ 

    [firstViewController release]; 
    [secondViewController release]; 
    [thirdViewController release]; 

    [super dealloc]; 

} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Release any cached data, images, etc that aren't in use. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    firstViewController = [[FirstViewController alloc] init]; 
    secondViewController = [[SecondViewController alloc] init]; 
    thirdViewController = [[ThirdViewController alloc] init]; 
    [self loadFirstView:nil]; 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

連接您的按鈕(你有沒有在你的項目,這也可能是這個問題做),你就完成了。

相關問題