這裏是我傳遞數據的按鈕函數。將數據傳遞給視圖控制器
問題是區域和國家的詳細信息傳遞給下一個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