ios项目开发(天气预报项目)

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

创建, 代码中使用了 静态的 tableviewcell

增加了 textview,url,json数据解析

部分代码片段:

[objc] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. //

  2. //  cityViewController.h

  3. //  weather1

  4. //

  5. //  Created by HeJiasheng on 13-11-12.

  6. //  Copyright (c) 2013年 HeJiasheng. All rights reserved.

  7. //

  8. #import <UIKit/UIKit.h>

  9. @interface cityViewController : UIViewController  

  10. @property (strong, nonatomic) IBOutlet UITextView *text1;  

  11. @property (strong, nonatomic) IBOutlet NSString *textcontent;  

  12. @end


[objc] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. - (void)viewDidLoad  

  2. {  

  3.    [super viewDidLoad];  

  4. self.text1.text= textcontent;  

  5. // Do any additional setup after loading the view.

  6. }  


[objc] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. //

  2. //  ViewController.h

  3. //  weather1

  4. //

  5. //  Created by HeJiasheng on 13-11-12.

  6. //  Copyright (c) 2013年 HeJiasheng. All rights reserved.

  7. //

  8. #import <UIKit/UIKit.h>

  9. @interface ViewController : UITableViewController  

  10. @end


ViewController.m 增加


[objc] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {  

  2. if ([segue.identifier isEqualToString:@"cityinfo"]) {  

  3. NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];  

  4. UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];  

  5. if ([[[cell textLabel] text] isEqualToString: @"北京"]) {  

  6. NSError *error;  

  7. NSURL *URL = [NSURL URLWithString:@"http://m.weather.com.cn/data/101010100.html"];  

  8. NSData *data = [NSData dataWithContentsOfURL:URL];  

  9. NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data  

  10. options:NSJSONReadingMutableContainers  

  11. error:&error];  

  12. NSDictionary *Info = [Dic objectForKey:@"weatherinfo"];  

  13. cityViewController *destViewController = segue.destinationViewController;  

  14.            destViewController.textcontent = [NSString stringWithFormat: @"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[Info objectForKey:@"date_y"],[Info objectForKey:@"week"],[Info objectForKey:@"city"], [Info objectForKey:@"weather1"], [Info objectForKey:@"temp1"]];  

  15.        }  

  16.    }  

  17. }  


你可能感兴趣的:(天气预报,项目开发,cocos2d-x,手游开发,中游学院)