这里是我传递数据的按钮函数。将数据传递给视图控制器
问题是区域和国家的详细信息传递给下一个ViewController,但经度和纬度返回null。
在ViewController.m:
- (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;
@end
在ForecastViewController.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];
}
请让我知道我在这里可能出错的地方。 我通过将数据记录到控制台进行检查。打印区域和国家,但经纬度为空值。
您没有向我们展示您设置经度和纬度的位置/方式。 – jcaron
我正在打印他们,看他们是否包含数据...并确保我没有通过零值.. ,他们不..我也检查了值... 正如我所说的区域和国家得到通过但其他两个不要...我很困惑 – Shravan
我编辑了我的问题,你可以看到我在哪里发送它们 – Shravan