2016-07-04 6 views
0

ViewController1UITableViewを実装し、TableViewセルの内容を配列に渡しています。モデルクラスを使用したUITableView配列

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

私は今

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

として、それを表示しています、私は静的を介してデータを通過してきた、私はモデルクラスを使用することにより、動的な方法を通してそれを実装したいです。

モデルクラス配列を使用して配列を変更するにはどうすればよいですか?

答えて

0

NSObjectの

から@interfaceのTableClassをオブジェクトクラスを作成します:NSObjectの

@property(アトミック、強い)のNSString *の点画。

あなたのViewControllerで

と輸入modelClass

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の*データ、NSURLResponse *応答、NSError *エラー){

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

}); 

}

TableClass * tableclassModel = [[TableClass ALLOC] INIT]。 tableclassModel = [_ tableArray objectAtIndex:indexPath.row];

cell.textLabel.text=tableclassModel.tittle; 
関連する問題