Cyph3r Cyph3r - 1 year ago 80
iOS Question

UITableView Array through Model Class

I have implemented a

,and I am passing the TableView cell content through the Array.

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

I have displayed it as

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

Now,I have passed the data through statically,I want to implement it through Dynamic way by using Model Class.

How can I alter the Array through Model Class Array...?

Answer Source

Create a object class From NSObject

@interface TableClass : NSObject


And import modelClass in your ViewController

dispatch_async(dispatch_get_main_queue(), ^{

NSURLSession*session=[NSURLSession sharedSession];

NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@""

] 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];

}]; [dataTask resume];



TableClass *tableclassModel=[[TableClass alloc]init]; tableclassModel=[_tableArray objectAtIndex:indexPath.row];