我已經構建了一個使用故事板的iOS 7應用程序。在我的offersViewController內,我有一個UIView和一個UITableView。 UIView作爲一個子視圖,在我的feed被解析的時候顯示一個加載消息。一旦完成子視圖被刪除,我的分析數據呈現在我的UITableView。TableView重新加載,當你離開然後返回
@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.myrssfeed.com"]]];
// 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];
}];
//Remove the loading screen
[loadingView removeFromSuperview];
//Show table data, if this is not here the table is empty.
[self.tableView reloadData];
}];
}
當我運行應用程序時,加載屏幕出現,然後表中顯示數據。如果我從此視圖控制器導航到另一個選項卡,然後導航回來,表格將閃爍。不太好的用戶體驗。該代碼行是[self.tableView reloadData];
。我需要這個或者表格變空。我究竟做錯了什麼?
什麼都沒有。但你不一定需要'viewDidAppear:'中的代碼...... – Wain
當然,它應該在-viewDidLoad中完成嗎?每當視圖出現時,tableView就會被重新加載,而不是一次,即在viewDidLoad中。 –
您正在重載tableView in viewDidAppear ...並且它意味着它會在每次出現視圖時重新載入數據...現在,如果您需要每次在視圖出現時重新載入tableView,請在ViewWillAppear中使用此代碼。如果你只想加載一次數據。拿這個代碼來viewDidLoad ... –