这是我传递数据的按钮函数。
问题是区域和国家详细信息被传递到下一个ViewController,但是纬度和经度返回null。
视图控件中的 :
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [[ForecastViewController alloc] init];
NSArray *seperate = [full componentsSeparatedByString:@", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(@"%@%@",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
}ForecastViewController.h中的
//
// ForecastViewController.h
// Weather App
//
// Created by Mac-Mini-2 on 10/02/16.
// Copyright © 2016 Mac-Mini-2. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Reachability.h>
@interface ForecastViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *place;
@property (weak, nonatomic) IBOutlet UITableView *table;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@property NSString *Area;
@property NSString *Country;
@property NSString *latitude;
@property NSString *longitude;
@endForecastViewController.m中的
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.table.delegate = self;
self.table.dataSource = self;
self.place.text = [NSString stringWithFormat:@"%@, %@",self.Area,self.Country];
locationName = [NSString stringWithFormat:@"%@, %@",self.Area,self.Country];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
metric = [defaults boolForKey:@"metric"];
Reachability *reach = [Reachability reachabilityWithHostName:@"www.google.com"];
NSInteger x = [reach currentReachabilityStatus];
if (x > 0)
{
reachable = YES;
NSLog(@"%@, %@",self.latitude,self.longitude);
[self getForecast:self.latitude longitudes:self.longitude];
}
else
{
reachable = NO;
[self getData];
errorMsg = @"Because of unavailability of Network Realtime information wont be available.";
[self performSelectorOnMainThread:@selector(displayAlert) withObject:NULL waitUntilDone:YES];
}
[reach startNotifier];
}请让我知道我在哪里可能出了问题。我通过将数据登录到控制台进行检查。该区域和国家是打印的,但经度和纬度为空值。
发布于 2016-02-24 14:18:38
如果您正在推动ForecastViewController,也许实现prepareForSegue:sender:是您的最佳选择。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"viewForecast"]){
NSArray *seperate = [full componentsSeparatedByString:@", "];
Area = seperate[0];
Country = seperate[1];
[(ForecastViewController *) [segue destinationViewController] setArea:area];
[(ForecastViewController *) [segue destinationViewController] setCountry:country];
...
...
}
}发布于 2016-02-24 14:27:28
我可以把经纬度作为数字存储在第一个控制器中吗?您确定'sendDetails.latitude‘和’经度‘在'ViewController’中设置正确吗?
发布于 2016-02-24 15:33:03
我认为您需要首先在ForecastViewController.h集合中编辑两点
@property (Strong, nonatomic) NSString *Area;
@property (Strong, nonatomic) NSString *Country;
@property (Strong, nonatomic) NSString *latitude;
@property (Strong, nonatomic) NSString *longitude;并在ForecastViewController.m中合成它。第二:-
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [self.storyboard instantiateViewControllerWithIdentifier:@"your ForecastViewController name in storyboard"];
NSArray *seperate = [full componentsSeparatedByString:@", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(@"%@%@",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
[self.navigationController pushViewController:sendDetails animated:YES];
}https://stackoverflow.com/questions/35604400
复制相似问题