版权声明:iOS技术小牛 https://blog.csdn.net/weixin_42925415/article/details/83412647
引导视图 viewcontroller
<UIScrollViewDelegate>{
UIPageControl *page;
UIScrollView *scV ;
}
scV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, lhW,lhH)];
scV.delegate = self;
scV.contentSize = CGSizeMake(3*lhW, lhW);
for (int i = 0 ; i< 3; i++) {
UIImageView *imgV = [[UIImageView alloc] initWithFrame:CGRectMake(i*lhW, 0, lhW , lhH)];
imgV.userInteractionEnabled = YES;
NSArray *imgVarr = @[@"u=96844630,4289301540&fm=27&gp=0",@"u=1731923468,4025707091&fm=27&gp=0",@"u=2683413938,272281277&fm=200&gp=0"];
imgV.image = [UIImage imageNamed:imgVarr[i]];
scV.pagingEnabled = YES;
scV.bounces = NO;
[scV addSubview:imgV];
if (i == 2) {
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(lhW-80, 5, 80, 40)];
btn.backgroundColor = [UIColor redColor];
[btn setTitle:@"立即体验" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(tiao) forControlEvents:UIControlEventTouchUpInside];
[imgV addSubview:btn];
}
}
[self.view addSubview:scV];
page = [[UIPageControl alloc] initWithFrame:CGRectMake((lhW-80)/2, lhH - 60, 80, 40)];
page.numberOfPages = 3;
page.pageIndicatorTintColor = [UIColor blueColor];
page.currentPageIndicatorTintColor = [UIColor redColor];
[self.view addSubview:page];
vc视图中的方法
#import "AFNetworking.h"
导入
//单元格 代理方法
<UITableViewDelegate,UITableViewDataSource>{
UITableView *table;
NSMutableArray *arr;
}
这是在 viewDidLoad 里面写的
table = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
table.delegate = self;
table.dataSource = self;
arr = [[NSMutableArray alloc]init];;
[self.view addSubview:table];
[table registerNib:[UINib nibWithNibName:@"faXianTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
[self setHttP];
//方法
-(void)setHttP{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
// [manager GET: @"" parameters:nil headers:nil progress:^(NSProgress * _Nonnull downloadProgress) {
NSMutableString *str = [NSMutableString stringWithString:@"http://mobile.ximalaya.com/mobile/v1/album/ts-1531886212572?ac=4G&albumId=14659743&device=iPhone&isAsc=true&pageSize=20&source=0&statEvent=pageview%2Falbum%4012610571&statModule=精品&statPage=tab%40发现_推荐&statPosition=1"];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[manager GET:str parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
// NSLog(@"%@",responseObject);
for (NSDictionary *dic in responseObject[@"data"][@"tracks"][@"list"]) {
NSLog(@"%@",dic);
BaseModel *model = [BaseModel new];
model.img = [dic objectForKey:@"coverLarge"];
model.time = [dic objectForKey:@"nickname"];
model.title = [dic objectForKey:@"title"];
[self->arr addObject:model];
}
// NSLog(@"%@",dic);
dispatch_async(dispatch_get_main_queue(), ^{
[self->table reloadData];
});
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@",error);
}];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//设置分区数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
table.rowHeight = 150;
faXianTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
BaseModel *model = arr[indexPath.row];
cell.imagV.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[arr[indexPath.row]img]]]];
cell.Zlabel.text = model.title;
cell.Slabel.text = model.time;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// http://live.ximalaya.com/live-web/v4/homepage?device=iPhone
oneViewController *one = [[oneViewController alloc] init];
[self.navigationController pushViewController:one animated:YES];
}
#import "oneViewController.h"
#import <WebKit/WebKit.h>
@interface oneViewController ()
@property(nonatomic,strong) WKWebView *webView;
@end
@implementation oneViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[WKWebView alloc] initWithFrame:self.view.frame];
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://live.ximalaya.com/live-web/v4/homepage?device=iPhone"]]];
self.webView.navigationDelegate = self;
self.webView.UIDelegate = self;
//开了支持滑动返回
self.webView.allowsBackForwardNavigationGestures = YES;
[self.view addSubview:self.webView];
}