2011-08-29 48 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未声明? –

相关问题