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

//图片

.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.L)