2009-11-18 171 views
0

您好我是ObjectiveC/iPhonehoneSDK的新手,我正在非正式地嘗試自行研究它。我基本上想要做的是從一個角度看有12個星座。當用戶點擊一個,它會進入第二個視圖(帶有動畫)並加載它在UILabel中點擊的星座的名稱,就是這樣。在視圖/視圖控制器之間傳遞變量

這裏是我的代碼: Lovescopes =第1頁 星座=第2頁

Lovescopes4AppDelegate.h

#import <UIKit/UIKit.h> 
#import "HoroscopesViewController.h" 
#import "Lovescopes4AppDelegate.h" 

@class Lovescopes4ViewController; 

@interface Lovescopes4AppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    Lovescopes4ViewController *viewController; 
HoroscopesViewController *horoscopesViewController; 
} 

-(void)loadHoroscope; 
-(void)loadMainPage; 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet Lovescopes4ViewController *viewController; 
@property (nonatomic, retain) HoroscopesViewController *horoscopesViewController; 
@end 

Lovescopes4AppDelegate.m

#import "Lovescopes4AppDelegate.h" 
#import "Lovescopes4ViewController.h" 

@implementation Lovescopes4AppDelegate 

@synthesize window; 
@synthesize viewController; 
@synthesize horoscopesViewController; 

-(void)loadHoroscope { 
HoroscopesViewController *aHoroscopeViewController = [[HoroscopesViewController alloc] initWithNibName:@"HoroscopesViewController" bundle:nil]; 
[self setHoroscopesViewController:aHoroscopeViewController]; 
[aHoroscopeViewController release]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; 
[viewController.view removeFromSuperview]; 
[self.window addSubview:[horoscopesViewController view]]; 
[UIView commitAnimations]; 
} 

-(void)loadMainPage { 
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:window cache:NO]; 
[horoscopesViewController.view removeFromSuperview]; 
[self.window addSubview:[viewController view]]; 
[UIView commitAnimations]; 
[horoscopesViewController release]; 
horoscopesViewController = nil; 
} 


- (void)applicationDidFinishLaunching:(UIApplication *)application {  

    // Override point for customization after app launch  
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 
} 


- (void)dealloc { 
    [viewController release]; 
    [window release]; 
    [super dealloc]; 
} 


@end 

Lovescopes4ViewController.h

#import <UIKit/UIKit.h> 
#import "HoroscopesViewController.h" 

@interface Lovescopes4ViewController : UIViewController { 
HoroscopesViewController *hvc; 
} 

-(IBAction)loadAries; 

@property (nonatomic, retain) HoroscopesViewController *hvc; 

@end 

Lovescope4ViewController.m

#import "Lovescopes4ViewController.h" 
#import "Lovescopes4AppDelegate.h" 

@implementation Lovescopes4ViewController 

@synthesize hvc; 


-(IBAction)loadAries { 


NSString *selected [email protected]"Aries"; 
[hvc loadZodiac:selected]; 


Lovescopes4AppDelegate *mainDelegate = (Lovescopes4AppDelegate *) [[UIApplication sharedApplication] delegate]; 
[mainDelegate loadHoroscope]; 
} 

HoroscopesViewController.h

#import <UIKit/UIKit.h> 


@interface HoroscopesViewController : UIViewController { 
IBOutlet UILabel *zodiacLabel; 
} 

-(void)loadZodiac:(id)zodiacSign; 
-(IBAction)back; 

@property (nonatomic, retain) IBOutlet UILabel *zodiacLabel; 

@end 

HoroscopesViewController.m

​​

回答

0

從我可以看到它好像你正在實現自己的導航功能視圖控制器。也許你應該看看這個指南:View Controller Programming Guide

如果你使用一個UINavigationController,你只需要在用戶點擊十二宮時做,就是把它傳遞給詳細視圖控制器(通過設置一個屬性,例如)然後使用[navigationController pushViewController:detailView animated:YES];推視圖控制器。

希望這會有所幫助!

相關問題