ios 引导页 新闻

首先修改 App Transport Security Settings

Allow Arbitrary Loads

Bundle name等

导入SDWebImage

AppDelegate.m中

#import "AppDelegate.h"

#import "ViewController.h"

#import "NewsViewController.h"

#import "DetailViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

NSUserDefaults *uf = [NSUserDefaults standardUserDefaults];

NSString *version = [uf objectForKey:@"systemVersion"];

NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];

if ([[dic objectForKey:@"CFBundleShortVersionString"] isEqualToString:version]) {

UITabBarController *tbc = [[UITabBarController alloc]init];

NewsViewController *nvc = [[NewsViewController alloc]init];

nvc.title = @"新闻播报";

nvc.tabBarItem.image = [UIImage imageNamed:@"1.png"];

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:nvc];

DetailViewController *dvc = [[DetailViewController alloc]init];

dvc.title = @"我的收藏";

dvc.tabBarItem.image = [UIImage imageNamed:@"1.png"];

UINavigationController *dnav = [[UINavigationController alloc]initWithRootViewController:dvc];

tbc.viewControllers = @[nav,dnav];

self.window.rootViewController = tbc;

}else{

ViewController *vc = [[ViewController alloc]init];

self.window.rootViewController = vc;

[uf setObject:[dic objectForKey:@"CFBundleShortVersionString"] forKey:@"systemVersion"];

}

return YES;

}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end

在LoadData.h中

#import

@interface LoadData : NSObject

+ (instancetype)shareLoadData;

- (void)getData;

@end

在LoadData.m中

#import "LoadData.h"

#import "Model.h"

static LoadData *ld;

@implementation LoadData

+ (instancetype)shareLoadData

{

if (!ld) {

ld = [[LoadData alloc]init];

}

return ld;

}

- (void)getData

{

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://api.jisuapi.com/news/get"]];

request.HTTPMethod = @"POST";

NSString *str = [NSString stringWithFormat:@"channel=%@&start=%d&num=%d&appkey=%@",@"头条",0,20,@"de394933e1a3e2db"];

NSData *bodyData = [str dataUsingEncoding:NSUTF8StringEncoding];

request.HTTPBody = bodyData;

NSURLSession *session = [NSURLSession sharedSession];

NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];

NSDictionary *dict = [dic objectForKey:@"result"];

NSArray *arr = [dict objectForKey:@"list"];

NSMutableArray *mArr = [NSMutableArray array];

for (NSDictionary *dictionary in arr) {

Model *m = [[Model alloc]init];

m.title = dictionary[@"title"];

m.pic = dictionary[@"pic"];

m.weburl = dictionary[@"weburl"];

[mArr addObject:m];

}

dispatch_async(dispatch_get_main_queue(), ^{

[[NSNotificationCenter defaultCenter]postNotificationName:@"data" object:mArr];

});

}];

[task resume];

}

@end

在ViewController.m中

#import "ViewController.h"

#import "AppDelegate.h"

#import "NewsViewController.h"

#import "DetailViewController.h"

@interface ViewController ()

{

UIScrollView *sv;

UIPageControl *pc;

NSArray *marr;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

marr = @[@"2",@"4",@"9"];

sv = [[UIScrollView alloc]initWithFrame:self.view.bounds];

sv.pagingEnabled = YES;

sv.bounces = NO;

sv.showsHorizontalScrollIndicator = YES;

sv.contentSize = CGSizeMake(self.view.frame.size.width*3, self.view.frame.size.height);

sv.delegate = self;

[self.view addSubview:sv];

for (int i = 0,x = 0; i < 3; i ++) {

UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(x, 0, self.view.frame.size.width, self.view.frame.size.height)];

img.image = [UIImage imageNamed:marr[i]];

[sv addSubview:img];

x += self.view.frame.size.width;

}

UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width*2, 450, self.view.frame.size.width, 44)];

[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];

[btn setTitle:@"立即体验" forState:UIControlStateNormal];

[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];

[sv addSubview:btn];

pc = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 500, self.view.frame.size.width, 44)];

pc.numberOfPages = 3;

[pc addTarget:self action:@selector(pageValueChanged:) forControlEvents:UIControlEventValueChanged];

[self.view addSubview:pc];

}

- (void)btnClicked

{

AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;

UITabBarController *tbc = [[UITabBarController alloc]init];

NewsViewController *nvc = [[NewsViewController alloc]init];

nvc.title = @"新闻播报";

nvc.tabBarItem.image = [UIImage imageNamed:@"1.png"];

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:nvc];

DetailViewController *dvc = [[DetailViewController alloc]init];

dvc.title = @"我的收藏";

dvc.tabBarItem.image = [UIImage imageNamed:@"1.png"];

UINavigationController *dnav = [[UINavigationController alloc]initWithRootViewController:dvc];

tbc.viewControllers = @[nav,dnav];

app.window.rootViewController = tbc;

}

- (void)pageValueChanged:(UIPageControl *)sender

{

sv.contentOffset = CGPointMake(sender.currentPage*self.view.frame.size.width, 0);

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

pc.currentPage = sv.contentOffset.x/self.view.frame.size.width;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

在NewsViewController.m中

#import "NewsViewController.h"

#import "LoadData.h"

#import "Model.h"

#import "UIImageView+WebCache.h"

#import "DetailViewController.h"

@interface NewsViewController ()

{

NSArray *arr;

UITableView *table;

}

@end

@implementation NewsViewController

- (void)viewDidLoad {

[super viewDidLoad];

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(notifiUpdate:) name:@"data" object:nil];

[[LoadData shareLoadData]getData];

table = [[UITableView alloc]initWithFrame:self.view.bounds];

table.dataSource = self;

table.delegate = self;

[table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cellid"];

[self.view addSubview:table];

}

- (void)notifiUpdate:(NSNotification *)notifi

{

arr = [notifi.object copy];

[table reloadData];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return arr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellid"];

Model *m = arr[indexPath.row];

cell.textLabel.text = m.title;

//    [cell.imageView setImageWithURL:[NSURL URLWithString:m.pic]];

//    cell.imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"m.pic"]]];

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

Model *m = arr[indexPath.row];

DetailViewController *dvc = [[DetailViewController alloc]init];

dvc.weburl = m.weburl;

[self.navigationController pushViewController:dvc animated:YES];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end

在DetailViewController.h中

#import

@interface DetailViewController : UIViewController

@property (nonatomic,strong)NSString *weburl;

@end

在DetailViewController.m中

#import "DetailViewController.h"

@interface DetailViewController ()

@end

@implementation DetailViewController

- (void)viewDidLoad {

[super viewDidLoad];

//

UIWebView *wv = [[UIWebView alloc]initWithFrame:self.view.bounds];

[wv loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.weburl]]];

[self.view addSubview:wv];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

/*

#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

// Get the new view controller using [segue destinationViewController].

// Pass the selected object to the new view controller.

}

*/

@end

在Model.h中

#import

@interface Model : NSObject

@property (nonatomic,strong)NSString *title,*pic,*weburl;

@end


著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

@synthesize executing=_executing;

@synthesize finished=_finished;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 212,185评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,445评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,684评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,564评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,681评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,874评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,025评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,761评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,217评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,545评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,694评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,351评论 4 332
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,988评论 3 315
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,778评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,007评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,427评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,580评论 2 349

推荐阅读更多精彩内容