溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ios項(xiàng)目:天氣預(yù)報(bào)

發(fā)布時(shí)間:2020-07-19 21:58:21 來源:網(wǎng)絡(luò) 閱讀:484 作者:中游學(xué)院 欄目:移動(dòng)開發(fā)

ios項(xiàng)目:天氣預(yù)報(bào)

ios項(xiàng)目:天氣預(yù)報(bào)

本項(xiàng)目基于 《使用storyboards建立 Navigation Controller and Table View》 http://uliweb.cpython.org/tutorial/view_chapter/424

創(chuàng)建, 代碼中使用了 靜態(tài)的 tableviewcell

增加了 textview,url,json數(shù)據(jù)解析

部分代碼片段:

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 <UIKit/UIKit.h>
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 <UIKit/UIKit.h>
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.}


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI