Iphone 在视图/视图控制器之间传递变量
嗨,我是ObjectiveC/IPhoneSDK的新手,我正在非正式地尝试自己研究它。我基本上想做的是从一个角度看,有12个星座。当用户单击一个图标时,它将进入第二个带有动画的视图,并在UILabel中加载它单击的黄道带的名称,就是它 这是我的密码: Lovescopes=第1页 占星术=第二页 Lovescopes4AppDelegate.hIphone 在视图/视图控制器之间传递变量,iphone,variables,views,Iphone,Variables,Views,嗨,我是ObjectiveC/IPhoneSDK的新手,我正在非正式地尝试自己研究它。我基本上想做的是从一个角度看,有12个星座。当用户单击一个图标时,它将进入第二个带有动画的视图,并在UILabel中加载它单击的黄道带的名称,就是它 这是我的密码: Lovescopes=第1页 占星术=第二页 Lovescopes4AppDelegate.h #import <UIKit/UIKit.h> #import "HoroscopesViewController.h" #import "
#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
Lovescopes4ViewController.h
#import <UIKit/UIKit.h>
#import "HoroscopesViewController.h"
@interface Lovescopes4ViewController : UIViewController {
HoroscopesViewController *hvc;
}
-(IBAction)loadAries;
@property (nonatomic, retain) HoroscopesViewController *hvc;
@end
#import <UIKit/UIKit.h>
@interface HoroscopesViewController : UIViewController {
IBOutlet UILabel *zodiacLabel;
}
-(void)loadZodiac:(id)zodiacSign;
-(IBAction)back;
@property (nonatomic, retain) IBOutlet UILabel *zodiacLabel;
@end
HoroscopesViewController.h
#import <UIKit/UIKit.h>
#import "HoroscopesViewController.h"
@interface Lovescopes4ViewController : UIViewController {
HoroscopesViewController *hvc;
}
-(IBAction)loadAries;
@property (nonatomic, retain) HoroscopesViewController *hvc;
@end
#import <UIKit/UIKit.h>
@interface HoroscopesViewController : UIViewController {
IBOutlet UILabel *zodiacLabel;
}
-(void)loadZodiac:(id)zodiacSign;
-(IBAction)back;
@property (nonatomic, retain) IBOutlet UILabel *zodiacLabel;
@end
从我看到的情况来看,您似乎正在实现自己的导航视图控制器功能。也许你应该看看这本指南: 如果使用UINavigationController,当用户单击黄道带时,只需通过设置属性将其传递给局部视图控制器,例如,然后使用[navigationController pushViewController:detailView animated:YES]推送视图控制器 希望这有帮助
#import "HoroscopesViewController.h"
#import "Lovescopes4AppDelegate.h"
@implementation HoroscopesViewController
@synthesize zodiacLabel;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
-(void)loadZodiac:(id)zodiacSign {
zodiacLabel.text = [NSString stringWithFormat: @"%@", zodiacSign];
}
-(IBAction)back {
Lovescopes4AppDelegate *mainDelegate = (Lovescopes4AppDelegate *) [[UIApplication sharedApplication] delegate];
[mainDelegate loadMainPage];
}