ios项目:天气预报-创新互联

ios项目:天气预报

创新互联公司致力于互联网网站建设与网站营销,提供网站设计制作、做网站、网站开发、seo优化、网站排名、互联网营销、成都小程序开发、公众号商城、等建站开发,创新互联公司网站建设策划专家,为不同类型的客户提供良好的互联网应用定制解决方案,帮助客户在新的全球化互联网环境中保持优势。

ios项目:天气预报

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

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

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

部分代码片段:

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.
9.#import 
10.
11.@interface cityViewController : UIViewController
12.
13.@property (strong, nonatomic) IBOutlet UITextView *text1;
14.@property (strong, nonatomic) IBOutlet NSString *textcontent;
15.@end
1.- (void)viewDidLoad
2.{
3.    [super viewDidLoad];
4.    self.text1.text= textcontent;
5.  // Do any additional setup after loading the view.
6.}
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.
9.#import 
10.
11.@interface ViewController : UITableViewController
12.
13.@end

ViewController.m 增加

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.      
6.        if ([[[cell textLabel] text] isEqualToString: @"北京"]) {
7.            NSError *error;
8.            NSURL *URL = [NSURL URLWithString:@"http://m.weather.com.cn/data/101010100.html"];
9.            NSData *data = [NSData dataWithContentsOfURL:URL];
10.            NSDictionary *Dic = [NSJSONSerialization JSONObjectWithData:data
11.                                                            options:NSJSONReadingMutableContainers
12.                                                            error:&error];
13.         
14.            NSDictionary *Info = [Dic objectForKey:@"weatherinfo"];
15.      
16.        cityViewController *destViewController = segue.destinationViewController;
17.          
18.            destViewController.textcontent = [NSString stringWithFormat: @"今天是 %@  %@  %@  的天气状况是:%@  %@ ",[Info objectForKey:@"date_y"],[Info objectForKey:@"week"],[Info objectForKey:@"city"], [Info objectForKey:@"weather1"], [Info objectForKey:@"temp1"]];
19.
20.        }
21.
22.    }
23.}

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享标题:ios项目:天气预报-创新互联
文章分享:http://pwwzsj.com/article/djsehi.html