您好訪問串我有兩個視圖控制器:FirstViewController和SecondViewController問題的從另一個類
FirstViewController.h
#import <UIKit/UIKit.h>
@interface FirstViewController: {
NSString *prStr;
}
-(IBAction)setString;
@property (nonatomic, retain) NSString *prStr;
@end
FirstViewController.m
#import"FirstViewController.h"
@implementation FirstViewController
@synthesize prStr;
-(IBAction)setString{
prStr = [[NSString alloc]initWithFormat:@"1"];
}
SecondViewController.h
#import <UIKit/UIKit.h>
@class FirstViewController;
@interface SecondViewController: {
FirstViewController *pr;
}
-(IBAction)example;
@property (nonatomic, retain) FirstViewController *pr;
@end
SecondViewController.m
#import"SecondViewController.h"
#import "FirstViewController.h"
@implementation SecondViewController
@synthesize pr;
-(IBAction)example{
NSLog(pr.prStr);
if([pr.prStr isEqualToString:@"1"]==YES){
//Do Something }
}
當我建立和運行應用程序,在前在IBAction的例子中,在調試器控制檯上沒有出現任何東西!如何從SecondViewController的操作中訪問FirstViewController的字符串,以便在調試器控制檯上顯示它?
問題解決了,我在的appdelegate宣佈的NSString和我用它作爲一個全局變量:我設置在字符串中第一視圖控制器和I使用appDelegate.prStr – Claudio 2010-11-26 10:58:21