有一种观点认为,我是在UIText中设定一种手法价值。 当我改变看法时,我希望把这一价值显示为“国际劳工联合会”。 我知道如何在一种观点中担任控制者,而不是两个观点之间。 我曾试图在称为“全球”的头号档案中确定红 code法的价值,然后回顾,但总是坠毁。 这里有一些编码样本:
这是全球文件。
#import <Foundation/Foundation.h>
@interface globals
extern NSString *zipCodeValue;
@end
这是全球文件:
#import "globals.h"
@implementation globals
NSString *zipCodeValue = @"default value";
@end
这是第一种观点(在案文领域加入正文法)。 接口和执行:
#import <UIKit/UIKit.h>
@interface ZipCodeEntryViewController : UIViewController <UITextFieldDelegate> {
UITextField *zipCode;
UIButton *doneButton;
}
@property (nonatomic, retain) IBOutlet UITextField *zipCode;
@property (nonatomic, retain) IBOutlet UIButton *doneButton;
-(IBAction) tapBackground:(id)sender;
-(IBAction) doneButtonClick:(id)doneButton;
@end
#import "ZipCodeEntryViewController.h"
#import "MillersAppAppDelegate.h"
#import "AddressViewController.h"
#import "globals.h"
#define MAX_LENGTH 5
@implementation ZipCodeEntryViewController
@synthesize zipCode, doneButton;
-(IBAction) doneButtonClick:(id)doneButton{
MillersAppAppDelegate *delegate = (MillersAppAppDelegate *)[[UIApplication sharedApplication] delegate];
AddressViewController *addressView = [[AddressViewController alloc]initWithNibName:@"AddressViewController" bundle:nil];
[delegate switchViews:self.view toView:addressView.view];
//using the global string to store the text field content
zipCodeValue=zipCode.text;
//the button is clicked and the view changes to addressView while NSLogging the correct value. So far, so good.
NSLog(@"%@", zipCodeValue);
[addressView release];
}
-(IBAction) tapBackground:(id)sender{
[zipCode resignFirstResponder];
}
因此,此时此刻,所有事情都看上去了(它正确指出)。 我假定不断变数的日冕堂纽埃现在将继续保留其固定价值,即使观点控制者已经改变。 当我试图在新的观点控制人(书记长)中适用时,它就没有标签。 这是我使用的方法(我把它命名在标题档案中;ZpCodeEntry是我称之为初始化并与“Interface Buildinger”目标相联系的IDLabel):
-(void)setZipCode{
zipCodeEntry.text=zipCodeValue;
}
I am now thoroughly confused, I have reason to believe my brain is missing something since I m new to this. Sorry if this is long-winded, I didn t want to leave anything out. I m clearly a beginner. AGGGG!!!