Ios 重新加载UITableView数据工作不正常
我有一个从我的Web服务接收的数组对象,用于填充UITableView。我试图实现一个方法,该方法从webservice获取一个新数组,并重新定义填充表的数组,然后重新加载tableView以使用该数组中的新对象。 这是应该做这项工作的方法:Ios 重新加载UITableView数据工作不正常,ios,uitableview,reload,Ios,Uitableview,Reload,我有一个从我的Web服务接收的数组对象,用于填充UITableView。我试图实现一个方法,该方法从webservice获取一个新数组,并重新定义填充表的数组,然后重新加载tableView以使用该数组中的新对象。 这是应该做这项工作的方法: WSCaller *caller = [[WSCaller alloc]init]; arrayFromWS = [caller getArray]; [self.table reloadData]; 但它不起作用。有什么想法吗 - (
WSCaller *caller = [[WSCaller alloc]init];
arrayFromWS = [caller getArray];
[self.table reloadData];
但它不起作用。有什么想法吗
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"productsCellIdentifier";
ProductsCell *cell = nil;
cell = (ProductsCell *)[self.table dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
NSArray *topLevelObjects = [[NSBundle mainBundle]loadNibNamed:@"ProductsCell" owner:nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[ProductsCell class]])
{
cell = (ProductsCell *)currentObject;
break;
}
}
}
if (productsMutableArray)
{
cell.backgroundColor = [UIColor whiteColor];
cell.productName.text = [[self.productsMutableArray objectAtIndex:indexPath.row]objectForKey:@"name"];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [productsMutableArray count];
}
您的数据源实现是错误的(或者至少代码片段是错误的) 首先,您没有保留arrayFromWS:
WSCaller *caller = [[WSCaller alloc] init];
arrayFromWS = [caller getArray];
[self.table reloadData];
其次,在tableView:numberOfRowsInSection:和tableView:cellForRowAtIndexPath:方法上,您使用的是不同的数组(ProductsTableArray)
为了解决这个问题,我建议更改上面的代码,例如(假设您的ProductsTableArray是一个strong/retain属性:
WSCaller *caller = [[WSCaller alloc] init];
self.productsMutableArray = [NSMutableArray arrayWithArray:[caller getArray]];
[self.table reloadData];
将
self.table
更改为self.tableView
。它不会使用数组中的新对象更新tableView
。如果我们看不到如何填充表视图,我们如何说,为什么您的表没有显示所需的信息?发布tableViewDelegate和tableViewDataSource方法。并详细说明错误(表根本不重新加载,或只是显示空表等)@gtm它仍然不起作用。=/是的,您是否可以将代码发布到您的UITableViewController
?正如@Morion所说,我们现在没有足够的信息。我认为,arrayFromWS只是从wev服务接收到的数组的抽象名称。表视图委托和数据源方法中的代码片段正如从真实代码复制和粘贴一样,我用数组组成tableView
的方式很好。我用新对象更改数组的方式也很好。我所需要的只是重新加载tableView
。我需要再次调用cellforrowatinexpath:
,因为它用于填充t表视图
已更改。