Iphone 在TableView IOS上首先添加新行
我想更新tableView中的数据,并将新数据作为UITableView中的新初始行插入。 我有两个数组:FileName数组包含使用ParseXM从服务器获取的数据,以及用于从FileNameArray复制的临时数组。我编写了一个函数UpdateArray来获取新数据,我将数据从FileNameArray复制到ViewDidLoad中的temp数组,然后调用UpdateArray;首先,我删除FileNameArray中的所有条目,然后向调用ParseXML的服务器发送请求,然后比较FileNameArray和temp Array,如果FileName arr>temp arr:删除temp arr中的所有条目并从FileName arr复制到temp arr,然后为UITableview重新加载数据,但tableView在第一行中不显示新数据 cellForRowAtIndexPath: 更新阵列: 当我调用UpdateArray时,虽然服务器有新数据,但这两个数组彼此相等,所以我的tableView不会更新。 你能告诉我解决办法吗?提前谢谢 编者按:Iphone 在TableView IOS上首先添加新行,iphone,ios,uitableview,object,add,Iphone,Ios,Uitableview,Object,Add,我想更新tableView中的数据,并将新数据作为UITableView中的新初始行插入。 我有两个数组:FileName数组包含使用ParseXM从服务器获取的数据,以及用于从FileNameArray复制的临时数组。我编写了一个函数UpdateArray来获取新数据,我将数据从FileNameArray复制到ViewDidLoad中的temp数组,然后调用UpdateArray;首先,我删除FileNameArray中的所有条目,然后向调用ParseXML的服务器发送请求,然后比较FileN
最初的措辞几乎难以理解——在更正时,我可能遗漏或误读了某些方面。强烈鼓励原作者校对 要更新表视图,必须根据需要更新数组 您可以将对象添加到以下位置:[yourArray insertObject:object atIndex:0]//第一排 然后使用新数组重新加载表:[yourTable reloadData] 这对你有用。@V-Xtreme的答案是正确的,另一个选项是 此外,为了完成这类工作,您需要使用insertRowsAtIndexPaths:withRowAnimation:Method,比如
[self.tableview insertRowsAtIndexPaths:indexPath withRowAnimation:YES ];
其中indexPath包含您要添加的行号。请在此处输入一些代码,说明您必须尝试的内容?首先在[tableview reloadData]之前更新数组。到目前为止您尝试了什么,如果尝试了,代码在哪里???我更新了代码。多谢了,他希望新的数据在顶部,那么你怎么能使用这个呢?
-(void)updateArray{
[NSThread sleepForTimeInterval:4.0];
[FileCompletedArray removeAllObjects];
...
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Success");
NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSLog(@"Response in Loop CompleteView: %@", parsexmlinput); //000400010001
// dispatch_async(dispatch_get_main_queue(), ^{
[self parseXMLFile:parsexmlinput];
NSLog(@"File Completed array: %@", FileCompletedArray);
NSLog(@"File Temp out array: %@", temp);
NSLog(@"File Completed count: %lu",(unsigned long)[ FileCompletedArray count]);
NSLog(@"File Temp out count: %lu", (unsigned long)[temp count]);
// NSLog(@"State: %@", state);
if([FileCompletedArray count ] != [temp count]) // compare 2 array
{
[temp removeallObjects];
temp = [FileCompletedArray mutableCopy];
[_tableView reloadData];
}
else
{
NSLog(@"2 array equal");
}
}
[self.tableview insertRowsAtIndexPaths:indexPath withRowAnimation:YES ];