美文网首页
IOS10json图片赋值,和表格赋值 ---by talent

IOS10json图片赋值,和表格赋值 ---by talent

作者: 天才iOS程序员 | 来源:发表于2017-03-19 18:22 被阅读13次

//图片

.h

@property (nonatomic , copy ) NSString * Name;

@property (nonatomic , strong ) NSString * image1;;

//        解析.m

self.view.backgroundColor =[UIColor whiteColor];

self.navigationItem.title =self.Name;

NSString *str = [[NSString stringWithFormat:@"%@",self.image1] stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];

NSURL * url =[NSURL URLWithString:str];

NSURLSession * session =[NSURLSession sharedSession];

dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); //创建信号量

//数据任务

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

UIImageView *image =[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 200, 150)];

image.image=[UIImage imageWithData:data];

[self.view addSubview:image];

dispatch_semaphore_signal(semaphore);  //发送信号

}];

[task resume];

dispatch_semaphore_wait(semaphore,DISPATCH_TIME_FOREVER);  //等待

.m

{

oneView *v;

NSMutableDictionary *dic;

NSMutableArray * arr;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

v =[[oneView alloc]initWithFrame:self.view.bounds];

self.view =v;

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

[[Model showData]getData1];

v.table.delegate=self;

v.table.dataSource =self;

v.table.rowHeight=80;

}

-(void)click:(NSNotification *)notifi{

arr =[notifi.object copy];

[v.table reloadData];

}

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

return arr.count;

}

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

static NSString * cellID=@"cell";

UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellID];

if (cell==nil) {

cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];

}

cell.textLabel.text =[NSString stringWithFormat:@"%@\n%@",[arr[indexPath.row] objectForKey:@"mname"],[arr[indexPath.row] objectForKey:@"person"]];

cell.textLabel.numberOfLines=0;

return cell;

}

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

TwoViewController *VC =[[TwoViewController alloc]init];

VC.theID =[arr[indexPath.row] objectForKey:@"id"];

VC.Name =[arr[indexPath.row] objectForKey:@"mname"];

VC.image1 =[arr[indexPath.row] objectForKey:@"image"];

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

}

相关文章

  • IOS10json图片赋值,和表格赋值 ---by talent

    //图片 .h @property (nonatomic , copy ) NSString * Name; @p...

  • 初始化渲染ECharts表格,layui 实现二级下拉动态赋值并

    html 初始化渲染ECharts表格 一级下拉先赋值 二级下拉框赋值并提交再次渲染表格

  • 解构赋值

    解构赋值 解构赋值可分为数组解构赋值和对象解构赋值,数组解构赋值要求右侧必须可迭代(具有Iterator 接口),...

  • es6解构赋值(数组解构)

    解构赋值什么是解构赋值左边和右边一一对应进行赋值解构赋值的分类数组解构赋值(重点) 对象解构赋值(重点)字符串解构...

  • iOS图片置灰

    通过对图片属性的操作,得到灰色图片赋值

  • 1.10赋值语句

    一、赋值语句 赋值语句形式 二、赋值的几种形式 元组及列表解包赋值(序列赋值)当你在“=”左侧编写元组和列表时,p...

  • 解构赋值

    解构赋值:ES6 中新增了变量赋值的方式,从数组和对象中提取值,对变量进行赋值。 单独赋值给变量,解构赋值。 解构...

  • 阻塞赋值和非阻塞赋值

    1.用always块描述组合逻辑时,应该使用阻塞赋值,比如二段式状态机 2.对时序逻辑的描述和建模应该使用非阻塞赋...

  • 【FPGA】赋值语句

    赋值语句应该是开发过程中使用最多的语句,在FPGA中,赋值语句分为“非阻塞赋值”和“阻塞赋值”,什么是“非阻塞赋值...

  • 2.变量的解构赋值

    数组的解构赋值对象的解构赋值字符串的解构赋值数值和布尔值的解构赋值函数参数的解构赋值圆括号问题用途

网友评论

      本文标题:IOS10json图片赋值,和表格赋值 ---by talent

      本文链接:https://www.haomeiwen.com/subject/yfhvnttx.html