导航栏按钮颜色
[self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
首先 定义数组属性
@property (nonatomic , strong)NSMutableArray *array;
创建 Model 类 继承 NSobject
定义属性
@property (nonatomic , strong)NSString *title;
@property (nonatomic , strong)NSString *time;
@property (nonatomic , strong)NSString *tu;
@property (nonatomic , strong)NSString *datatitle;
-(void)addnet{
//GET 请求
//创建网络路径
NSURL *url = [NSURL URLWithString:@"http://127.0.0.1/Property.json"];
//创建网络请求
NSURLRequest *request = [NSURLRequest requestWithURL:url];
//获取会话对象
NSURLSession *session = [NSURLSession sharedSession];
//根据会话对象 创建一个task任务
NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
//对服务器返回的数据进行处理
if (error) {
NSLog(@"请求数据失败");
}else{
//NSLog(@"%@",[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
NSArray *arr = dict[@"restuts"];
for (NSDictionary *dic in arr) {
Model *mo = [[Model alloc]init];
[mo setValuesForKeysWithDictionary:dic];
[self->_array addObject:mo];
dispatch_async(dispatch_get_main_queue(), ^{
[self->_tbV reloadData];
});
}
}
}];
//执行任务
[sessionTask resume];
}
.m中
Model *model = self.array[indexPath.row];
cell.imageView.image = [UIImage imageNamed:model.tu];
cell.textLabel.text =model.title;
cell.detailTextLabel.text = model.datatitle;
cell.detailTextLabel.textColor = [UIColor lightGrayColor];