你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> ios項目開發(天氣預報項目):

ios項目開發(天氣預報項目):

編輯:IOS開發綜合

 

 

創建, 代碼中使用了 靜態的 tableviewcell

增加了 textview,url,json數據解析

部分代碼片段:

 

//
//  cityViewController.h
//  weather1
//
//  Created by HeJiasheng on 13-11-12.
//  Copyright (c) 2013年 HeJiasheng. All rights reserved.
//
#import 
@interface cityViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextView *text1;
@property (strong, nonatomic) IBOutlet NSString *textcontent;
@end

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.text1.text= textcontent;
	// Do any additional setup after loading the view.
}

//
//  ViewController.h
//  weather1
//
//  Created by HeJiasheng on 13-11-12.
//  Copyright (c) 2013年 HeJiasheng. All rights reserved.
//
#import 
@interface ViewController : UITableViewController
@end

ViewController.m 增加

 

 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@cityinfo]) {
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        
        if ([[[cell textLabel] text] isEqualToString: @北京]) {
            NSError *error;
            NSURL *URL = [NSURL URLWithString:@http://m.weather.com.cn/data/101010100.html];
            NSData *data = [NSData dataWithContentsOfURL:URL];
            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data
                                                            options:NSJSONReadingMutableContainers
                                                            error:&error];
           
            NSDictionary *Info = [Dic objectForKey:@weatherinfo];
        
        cityViewController *destViewController = segue.destinationViewController;
            
            destViewController.textcontent = [NSString stringWithFormat: @今天是 %@  %@  %@  的天氣狀況是:%@  %@ ,[Info objectForKey:@date_y],[Info objectForKey:@week],[Info objectForKey:@city], [Info objectForKey:@weather1], [Info objectForKey:@temp1]];
  
        }
    }
}


 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved