码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-05-13 08:19:24      阅读:423      评论:0      收藏:0      [点我收藏+]

标签: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"]];
  
        }
    }
}


ios项目开发(天气预报项目):,布布扣,bubuko.com

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

标签:ios项目   ios培训   cocos2d-x培训   中游学院   天气预报   

原文地址:http://blog.csdn.net/woshiwupo/article/details/25589095

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!