我正在尝试制作一个从气象站获取数据的应用程序。它是一个基于标签栏的应用程序。我有两个视图控制器:FirstViewController 和 SecondViewController。
在 FirstViewController 中,我完成了大部分工作。使用来自 xml 解析的值并将这些值分配给 UILabel。那工作正常。我正在使用 if() 来根据风的角度为 UILabel 分配风的名称,例如:
在我的 FirstViewController.m
-(void)setWindDirectionName
{
if(windDirectionAngle >= 0 && windDirectionAngle <=11.25f) labelWindDirectionName.text = @"N";
if(windDirectionAngle > 11.25f && windDirectionAngle <=33.75f) labelWindDirectionName.text = @"NNE";
if(windDirectionAngle > 33.75f && windDirectionAngle <= 56.25f) labelWindDirectionName.text = @"NE";
if(windDirectionAngle > 56.25f && windDirectionAngle <=78.75f) labelWindDirectionName.text = @"ENE";
if(windDirectionAngle > 78.75f && windDirectionAngle <=101.25f) labelWindDirectionName.text = @"E";
.
.
. so on
在 SecondViewController我有 UILabel 并希望它从FirstViewController获取labelWindDirectionName.text的值。
我的 SecondViewController.h
@interface SecondViewController : UIViewController <CLLocationManagerDelegate>
{
NSString *windName;
}
@property (strong,nonatomic) NSString *windName;
@property (strong, nonatomic) IBOutlet UILabel *labelCompassViewWindDirectionName;
@end
并在 SecondViewController.m
FirstViewController *fvc = [[FirstViewController alloc]init];
windName = fvc.labelWindDirectionName.text;
labelCompassViewWindDirectionName.text = windName;//getting null probably making completely new object;
如何将数据(UILABEL.TEXT)传递到基于标签栏的应用程序中的另一个视图?我在哪里犯错?谢谢