English 中文(简体)
• 如何进口 数值 观点主计长
原标题:How To Import NSString Value Into A Different View Controller?

有一种观点认为,我是在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!!!

最佳回答

利用NSUserDefaults:

NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setObject:zipCodeValue forKey:@"myKey"];
[ud synchronize];

And to load it:

NSString *a = [ud objectForKey:@"myKey"];

你们可以在你们的心目中装满和拯救它。

问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签