0

wunderground api を使用する天気予報アプリを作成しようとしています... apiKey を取得し、以下のコードでそれを使用しましたが、デバッグ領域に結果が表示されません... Xcode で警告が表示されます「EXPRESSION RESULT UNUSED」の行に...これは問題ですか?誰でも私を助けてもらえますか?

#import "WeatherForecast.h"
#import "MainViewController.h"

@implementation WeatherForecast

- (void) queryServiceWithState:(NSString *)state
                andCity:(NSString *)city
                withParent:(UIViewController *)controller {
viewController = (MainViewController *)controller;
responseData = [NSMutableData data];
apiKey = @"c5f79118382c6e91";

NSString *url =
[NSString stringWithFormat:
 @"http://api.wunderground.com/api/%@/conditions/q/%@//%@.xml",
 apiKey, state, city];

theURL = [NSURL URLWithString:url];
NSURLRequest *request = [NSURLRequest requestWithURL:theURL];
[[NSURLConnection alloc] initWithRequest:request delegate:self];//EXPRESSION RESULT     UNUSED
}


#pragma mark NSURLConnection Delegate Methods

- (NSURLRequest *)connection:(NSURLConnection *)connection
         willSendRequest:(NSURLRequest *)request
        redirectResponse:(NSURLResponse *)response{
@autoreleasepool {
    theURL = [request URL];
}
return request;
}

- (void)connection:(NSURLConnection *)connection
didReceiveResponse:(NSURLResponse *)response {
[responseData setLength:0];
}


-(void)connection:(NSURLConnection *)connection
didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Error = %@",error);
}

- (void)connectionDidFinishiLoading: (NSURLConnection *)connection {
NSString *content =
[[NSString alloc]initWithBytes:[responseData bytes]
                        length:[responseData length]
                      encoding:NSUTF8StringEncoding];
NSLog ( @"Data = %@",content);

//...Insert code to parse the content here...

[viewController updateView];

}

@end

アプリ用に別の 2 つの .m ファイルがあります。エラーはこのファイルの 1 つにある可能性があります

#import "MainViewController.h"
#import "WeatherForecast.h"

@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad
{
 [super viewDidLoad];
[self refreshView:self];
}

- (IBAction)refreshView:(id)sender {
 [loadingActivityIndicator startAnimating];
 [self.forecast queryServiceWithState:@"UK" andCity:@"London" withParent:self];
}


- (void)updateView {

//...

[loadingActivityIndicator stopAnimating];
} 

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Flipside View

- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)showInfo:(id)sender
{    
FlipsideViewController *controller = [[FlipsideViewController alloc]               

initWithNibName:@"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}

@end

#import "AppDelegate.h"
#import "WeatherForecast.h"
#import "MainViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    

(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.mainViewController = [[MainViewController alloc]     

initWithNibName:@"MainViewController" bundle:nil];

WeatherForecast *forecast = [[WeatherForecast alloc] init];
self.mainViewController.forecast = forecast;


self.window.rootViewController = self.mainViewController;
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{

}

- (void)applicationDidEnterBackground:(UIApplication *)application
{

}

- (void)applicationWillEnterForeground:(UIApplication *)application
{

}

- (void)applicationDidBecomeActive:(UIApplication *)application
{

}

- (void)applicationWillTerminate:(UIApplication *)application
{

}

@end

インターネット接続をオフにしようとすると、デバッグ領域に「エラーメッセージ」が表示されますが、インターネット接続をオンにすると、アクティビティインジケーターが永遠に回転するだけです...

ご回答ありがとうございます....私は失われた感じです...

4

1 に答える 1

0

取得する場所EXPRESSION RESULT UNUSEDは、接続オブジェクトです。通常、それをプロパティに保存して、まだ使用している間に破棄されないようにする必要があります。

于 2013-07-20T22:12:44.037 に答える