【发布时间】:2016-02-24 14:08:14
【问题描述】:
这是我传递数据的按钮功能。
问题是地区和国家详细信息被传递到下一个 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];
}
请让我知道我可能在哪里出错了。 我通过将数据记录到控制台来检查。打印区域和国家,但经度和纬度给出空值。
【问题讨论】:
-
您没有向我们展示您在何处/如何设置经度和纬度。
-
我正在打印它们以查看它们是否包含数据......并确保我没有传递 nil 值......它们不是......我也检查了这些值......正如我所说地区和国家通过,但其他两个不...我很困惑
-
我已经编辑了我的问题,你可以看到我现在将它们发送到哪里
-
你在哪里设置经纬度
-
您的代码中显然缺少一些东西...在
forecast:方法中,您分配了一个ForecastViewController,设置了它的一些属性,然后不对其进行任何操作(所以它被丢弃了)。您在哪里/如何展示新的视图控制器?您不会在情节提要中使用转场吗?
标签: ios objective-c