Ios 无法在tableview中显示数据
我正在从服务器获取数据,但无法在Ios 无法在tableview中显示数据,ios,objective-c,uitableview,tableviewcell,completionhandler,Ios,Objective C,Uitableview,Tableviewcell,Completionhandler,我正在从服务器获取数据,但无法在tableview中显示它…我正在jsonarray变量中存储数据..但它显示为jsonarray.count在完成处理程序外为零。(第节中的行数numberofrowsin) @interface Staffdir() @属性(非原子,强)NSMutableArray*jsonarr; @结束 @实现Staffdir -(无效)viewDidLoad{ _namesarr=[[NSMutableArray alloc]init]; _职业arr=[[NSMuta
tableview
中显示它…我正在jsonarray
变量中存储数据..但它显示为jsonarray.count
在完成处理程序外为零。(第节中的行数numberofrowsin
)
@interface Staffdir()
@属性(非原子,强)NSMutableArray*jsonarr;
@结束
@实现Staffdir
-(无效)viewDidLoad{
_namesarr=[[NSMutableArray alloc]init];
_职业arr=[[NSMutableArray alloc]init];
_Phonearr=[[NSMutableArray alloc]init];
_faxnumarr=[[NSMutableArray alloc]init];
NSMutableURLRequest*req=[[NSMutableURLRequest alloc]init];
NSURL*url=[NSURL URLWithString:@“http:someurl”];
[req setURL:url];
[[[NSURLSession sharedSession]dataTaskWithRequest:req completionHandler:^(NSData*\u可为空的数据,NSURLSession*\u可为空的响应,NSError*\u可为空的错误){
self.jsonarr=[NSJSONSerialization JSONObjectWithData:data
选项:针织品
错误:&错误];
NSDictionary*dict=[[NSDictionary alloc]init];
对于(int i=0;i请尝试以下方法:
从服务器获取数据
[json PostMethod:method parameters:parameter success:^(NSDictionary *responseDict){
response=[[NSMutableArray alloc]init];
for (int i=0; i < [[responseDict valueForKey:@"transactions"] count]; i++) {
[response addObject:[[responseDict valueForKey:@"transactions"]objectAtIndex:i]];
}
[self.tableView reloadData];
检查它,如果您仍然面临错误,请更新我。我将提供帮助,如果您提供响应,这将帮助我轻松解决问题。dataTaskWithRequest
已经是asycn,无需调用调度。您需要调用[self.tableview reloadData];
在完成处理程序中。您确定返回请求的数据有值吗?。如果是,请向我们显示json响应的结构。尝试此NSDictionary*响应=[[NSDictionary alloc]init];响应=[[NSMutableArray alloc]init];for(int i=0;i<[[ResponseDictionary valueForKey:@“DictionaryName”]count];i++){[response addObject:[[responseDict valueForKey:@“name”]objectAtIndex:i]];}[self.tableView reloadData];
[json PostMethod:method parameters:parameter success:^(NSDictionary *responseDict){
response=[[NSMutableArray alloc]init];
for (int i=0; i < [[responseDict valueForKey:@"transactions"] count]; i++) {
[response addObject:[[responseDict valueForKey:@"transactions"]objectAtIndex:i]];
}
[self.tableView reloadData];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if ([response count] > 0) {
//creating the status lable
UILabel * name = [[UILabel alloc]initWithFrame:CGRectMake( 80*XScale, 25*YScale, XScale*200, YScale*15)];
name.font = [UIFont fontWithName:@"STHeitiSC-Medium" size:12.0f];
NSString *time=[[response objectAtIndex:indexPath.row]valueForKey:@“name”];
[cell.contentView addSubview:name];