Ios 将customTableView添加到未正确加载json数据的视图中

Ios 将customTableView添加到未正确加载json数据的视图中,ios,objective-c,json,uitableview,Ios,Objective C,Json,Uitableview,在viewController中,我想在viewController上显示/添加子视图我的VoidTableView。我在ViewDidLoad中使用了以下代码将其添加到viewController,它确实会相应地出现在我的viewController上,但不会加载数据 // VoidTableView VoidTableView *controllerVoid; UITableView *voidTableView ; controllerVoid = [[VoidTableView all

在viewController中,我想在viewController上显示/添加子视图我的VoidTableView。我在ViewDidLoad中使用了以下代码将其添加到viewController,它确实会相应地出现在我的viewController上,但不会加载数据

// VoidTableView
VoidTableView *controllerVoid;
UITableView *voidTableView ;

controllerVoid = [[VoidTableView alloc]init];
voidTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 222, 481, 400)];
voidTableView.delegate = controllerVoid;
voidTableView.dataSource = controllerVoid; 
在我的VoidTableView.m文件中,我有一个使用webAPI检索json数据并将其保存到_dataarray的方法。我正在获取数据,但它没有显示在表上。当我返回一个整数而不是numberOfRows的_dataarray.count时,表将加载但带有(null)值。当我返回_dataarray.count时,表似乎根本没有加载。我认为在将数组加载到cellForRowAtIndexPath方法中缺少了一个关键步骤。有人能帮忙吗

编辑:\ U dataarray是在VoidTableView.h中声明的NSArray属性。下面是我的表视图代码,我在VoidTableView.m中有一个loadSalesHistory方法,它将所有数据保存到_dataarray中

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

即使数据被保存到_dataarray中,计数仍然表示为0

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"////// %lu",(unsigned long)_dataarray.count); // is 0
return [_dataarray count];
//  return 3;
}
CellForRowatinex应该是大多数人编写它的标准

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell ;
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

if (cell == nil){

}
UILabel *cusdata = [[UILabel alloc] initWithFrame:CGRectMake(05, 10, 300, cell.bounds.size.height)];
NSString *datestr = [[_dataarray objectAtIndex:indexPath.row] valueForKey:@"Date"];
NSString *timestr = [[_dataarray objectAtIndex:indexPath.row] valueForKey:@"Time"];

NSString *amountstr = [[_dataarray objectAtIndex:indexPath.row] valueForKey:@"SoldAmount"];
amountstr = [NSString stringWithFormat:@"$%@",amountstr];
NSNumber *pointsstr = [[_dataarray objectAtIndex:indexPath.row] valueForKey:@"Points"];
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(230, 12, 70, 40)];
UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(370, 12, 70, 40)];
label2.textAlignment = NSTextAlignmentCenter ;
label3.textAlignment = NSTextAlignmentCenter ;
label2.text = amountstr ;
label3.text = [NSString stringWithFormat:@"%@",pointsstr] ;
[cell.contentView addSubview:label2];
[cell.contentView addSubview:label3] ;

NSString *cusdatastr = [NSString stringWithFormat:@"%@         %@    ",datestr,timestr];
[cell.contentView addSubview:cusdata];
cusdata.text = cusdatastr ;

return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

return 60 ;
}

我还将NSLog放在了ViewDidLoad中的VoidViewTable中,但即使我加载了表格,它也不会出现。这可能是问题所在吗

首先,除非执行逻辑检查是否已将对象添加到子视图中,否则切勿将添加内容添加到单元格的内容视图中

第二,跟随者返回对话框的答案,并放入
[tablewView reloadData]didReceiveResponse:
NSURLConnection的委托方法


您还需要将表视图添加到新创建的视图的子视图(ViewDiLoad或ViewWillDisplay)。

您多次提到\u dataarray,您是否打算让我们都对它是什么以及它在代码中的使用位置感到不安?@MartinH抱歉,我已更新了我的帖子您的帖子中仍然没有任何内容,只有几行内容。使用表视图有几种方法必须实现。他们在哪里?你现在已经被否决了很多次,也许最好删除这个问题,用更多的代码开始一个新问题,人们不会因为否决票而看这个问题“计数仍然是0”。然后你需要找出原因。如果没有,则无法显示数据