Ios UITableView在重新加载时闪烁
在UIViewController上,我有一个UIView和一个UITableView。当我的XML解析器(RaptureXML)解析表数据时,UIView充当加载屏幕。完成后,将在UITableView中显示数据 但是,当我运行应用程序并导航到其他视图控制器然后返回时,UITableView由于Ios UITableView在重新加载时闪烁,ios,objective-c,uitableview,uiview,uiviewcontroller,Ios,Objective C,Uitableview,Uiview,Uiviewcontroller,在UIViewController上,我有一个UIView和一个UITableView。当我的XML解析器(RaptureXML)解析表数据时,UIView充当加载屏幕。完成后,将在UITableView中显示数据 但是,当我运行应用程序并导航到其他视图控制器然后返回时,UITableView由于[self.tableView reloadData]而闪烁如果我取出它,它不会显示表中的数据。我能把这个搬到别的地方吗 @interface OffersViewController () @end
[self.tableView reloadData]而闪烁代码>如果我取出它,它不会显示表中的数据。我能把这个搬到别的地方吗
@interface OffersViewController ()
@end
@implementation OffersViewController
@synthesize loadingView;
MoreCobaltOffers *currentFeed;
AppDelegate *appDelegate;
- (void)viewDidAppear:(BOOL)animated
{
[self.tableView addSubview:loadingView];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Navigation"]];
CustomStringParser *customStringParser = [[CustomStringParser alloc] init];
// Download and parse XML data
RXMLElement *rxml = [RXMLElement elementFromXMLData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.morecobalt.co.uk/rss/?t=offers"]]];
// Create an reference to AppDelegate
appDelegate = [[UIApplication sharedApplication] delegate];
// Create an array to store each feed
appDelegate.offersFeeds = [[NSMutableArray alloc] init];
// Loop Through XML Data
[rxml iterate:@"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:@"item" usingBlock:^(RXMLElement *repElement) {
// Assign element to string
NSString *title = [repElement child:@"title"].text;
NSString *subtitle = [repElement child:@"tagline"].text;
NSString *description = [repElement child:@"description"].text;
NSString *imageurl = [repElement child:@"image"].text;
NSString *address = [repElement child:@"address"].text;
// Assign element value to MoreCobalt.h propertys
currentFeed = [MoreCobaltOffers alloc];
currentFeed.title = title;
currentFeed.imageurl = imageurl;
currentFeed.addressline = address;
// DESCRIPTION FORMATTING
description = [customStringParser parseHTML:description];
description = [customStringParser parseLinesMultiple:description];
description = [customStringParser removeSocialSignifiers:description];
description = [customStringParser appendTermsOfUse:description];
currentFeed.description = description;
// SUBTITLE FORMATTING
subtitle = [customStringParser parseHTML:subtitle];
subtitle = [customStringParser parseLinesSingle:subtitle];
subtitle = [customStringParser removeSocialSignifiers:subtitle];
currentFeed.subtitle = subtitle;
// Add a new object to the feeds array
[[appDelegate offersFeeds] addObject:currentFeed];
}];
[loadingView removeFromSuperview];
[self.tableView reloadData];
}];
}
您正在将视图添加到TableView之前。只需在界面生成器中更改顺序
以下是您的视图层次结构:
View
View
GrayActivity Indicator
Label - Loading
Table View
TableViewCell
以下是假设的情况:
View
Table View
TableViewCell
View
GrayActivity Indicator
Label - Loading
编辑
请删除此行“[loadingView setHidden:是];将代码更新为以下内容:
[rxml iterate:@"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:@"item" usingBlock:^(RXMLElement *repElement) {
.
.
.
[[appDelegate offersFeeds] addObject:currentFeed];
}];
dispatch_sync(dispatch_get_main_queue(), ^{
[loadingView setHidden:YES];
[self.table reloadData];
});
}]) 像这样重新构造代码,我认为它应该可以工作
// Loop Through XML Data
[rxml iterate:@"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:@"item" usingBlock:^(RXMLElement *repElement) {
[loadingView setHidden:No];
...
...
...
...
...
...
[loadingView setHidden:YES];
}];
}];
在块中添加代码时,此代码在另一个线程中执行,视图设置为快速隐藏,但如果您注释[loadingView setHidden:YES]代码>必须显示视图。是,这是正确的。如果您评论[loadingView setHidden:YES];将显示该视图。您建议我们如何解决此问题?找到管理块完成的正确方法并将此代码放入其中。您知道如何做到这一点吗?我从未使用过RXMLElement,抱歉:(谢谢,这样做了,但没有解决我的问题。您仍然看不到加载视图和表视图?您可以对[loadingView setHidden:YES]行进行注释吗;并告诉我加载视图是否可见?您好,如果我对该行进行注释,加载视图是可见的。无论是否未注释,我都看不到加载视图。我相信这与我的块有关。我编辑了我的答案,似乎您的xml加载是异步的,因此,got击中了该行[loadingView setHidden:YES],在块中的代码完成之前。是的,xml加载是异步的。我添加了您所说的内容,但是现在应用程序卡在其启动映像上:(这样做不会显示加载视图