2011-08-29 75 views
0

您好,我有一個問題,將數值從其他班級調整到一個班級。基本上在我的項目中,我有一個班級placeTableView這是表視圖類。通過授權從班級發送數據時出現問題

in placesTableView.m 
{ 
mapView *map=[[mapView alloc]init]; 
[email protected]"london"; 

} 


mapView.h - a class where delegate is defined and from this class i want to send data to  confirmController 

@protocol mapViewDelegate; 

@interface mapView : UIViewController { 


id <mapViewDelegate> delegate;// 
} 
@property (nonatomic, assign) id delegate;// 


@end 
@protocol mapViewDelegate <NSObject>// 

-(void)sendAStringToAnotherView:(NSString*)string; 
@end 

mapView.m

@synthesis townName; 
-(void)viewDidLoad{ 


label.text=townName;//townName is getting value from previous view n showing here. 


NSLog(@"%@",townName);//it shows value of townName so townName definetly contains value 

// NSString *a=[NSString stringWithFormat:@"%@",townName]; 

[delegate sendAStringToAnotherView:townName]; // this is sending method. i think problem is here 
} 

confirmController.m - 在數據發送

-(void)viewDidLoad{ 

mapView *myViewControllerPointer=[[mapView alloc] init]; 
myViewControllerPointer.delegate = self;// 

[self.view addSubview:self.myViewControllerPointer.view]; 

} 

-(void)sendAStringToAnotherView:(NSString*)string 
{ 
//displays the string as console output 
NSLog(@"lolo%@", [NSString stringWithFormat:@"%@",string]); // i want to show values here 
} 

現在我想顯示townName在confirmController從MapView的一類。但它顯示爲空。但在mapView如果我使用字符串代替townName它顯示在這裏confirmController

回答

0

您必須在appDelegate中創建必要的變量,並將其屬性設置爲.h,並在.m文件中進行合成。現在你可以在你的第一個類中爲這個變量設置值,並使用appDalegate變量獲得目標類的值

+0

好的你說我必須在應用程序委託類中聲明變量。並再次聲明它們並將它們的屬性設置在mapView類和mapView.m文件中,我可以將值放入它們中。並在confirmController類中我想訪問它們,我可以訪問他們使用應用程序變量?如何請更多地闡述 –

+0

或者我必須在應用程序委託類中設置屬性n合成? –

+0

我在應用程序委託類設置屬性和sysnthsis那裏設置變量。現在在我的發件人班如何設置值?我在應用程序委託類中聲明的變量是globalVariable。但在發件人類globalVariable是showin未聲明? –

相關問題