通过模型的 UITableView 数组 Class

UITableView Array through Model Class

我在 ViewController1 中实现了 UITableView,我正在通过数组传递 TableView 单元格内容。

_tableData=[[NSMutableArray alloc]initWithObjects:@"1",@"2" ,@"3",@"4",nil];

我已经显示为

cell.detailTextLabel.text=[_tableData objectAtIndex:indexPath.row];

现在,我已经静态地传递了数据,我想通过使用模型Class的动态方式实现它。

如何通过模型 Class 数组改变数组...?

从 NSObject

创建一个 object class

@interface 表类:NSObject

@属性(非原子,强)NSString*标题;

并在您的 ViewController

中导入模型类

dispatch_async(dispatch_get_main_queue(), ^{

NSURLSession*session=[NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=music"

] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    NSLog(@"%@", json);

    NSArray*entryarr=[json objectForKey:@"results"];


    for (NSDictionary*appDict in entryarr) {
        TableClass*tc=[[TableClass alloc]init];


        //setting tittler

        NSString*str=[appDict objectForKey:@"artistName"];
        [tc setTittle:str];

        NSLog(@"artist Name=%@",tc.tittle);







        [_tableArray addObject:tc];

    }


    [self.tableView reloadData];

}]; [数据任务恢复];

});

}

TableClass *tableclassModel=[[TableClass alloc]init]; tableclass模型=[_table数组objectAtIndex:indexPath.row];

cell.textLabel.text=tableclassModel.tittle;