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

來源:互聯網
上載者:User

標籤:ios項目   ios培訓   cocos2d-x培訓   中遊學院   天氣預報   

本項目基於 《使用storyboards建立 Navigation Controller and Table View》 http://uliweb.cpython.org/tutorial/view_chapter/424

建立, 代碼中使用了 靜態 tableviewcell

增加了 textview,url,json資料解析

部分程式碼片段: 

////  cityViewController.h//  weather1////  Created by HeJiasheng on 13-11-12.//  Copyright (c) 2013年 HeJiasheng. All rights reserved.//#import <UIKit/UIKit.h>@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 <UIKit/UIKit.h>@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"]];          }    }}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.