0

在我的 UIViewController 上,我有一个 UIView 和一个 UITableView。UIView 充当加载屏幕,而我的 XML Parser (RaptureXML) 正在解析表数据。完成后,它会在 UITableView 中显示数据。

但是,当我运行应用程序并导航到不同的视图控制器然后返回时,UITableView 会闪烁,因为[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];
}];
}
4

2 回答 2

2

您在 TableView 之前添加视图。只需在界面生成器中更改顺序即可。

这是您查看层次结构:

View
  View
     GrayActivity Indicator
     Label  - Loading
  Table View
    TableViewCell

这是假设的方式:

View
  Table View
    TableViewCell
  View
     GrayActivity Indicator
     Label  - Loading

编辑

请删除此行 `[loadingView setHidden:YES]; 将您的代码更新为以下内容:

[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];
});

}];

于 2013-10-31T18:19:15.900 回答
0

像这样重组你的代码,我认为它应该可以工作

// Loop Through XML Data
[rxml iterate:@"channel" usingBlock:^(RXMLElement *supportElement) {
[supportElement iterate:@"item" usingBlock:^(RXMLElement *repElement) {
[loadingView setHidden:No];
...
...
...
...
...
...
[loadingView setHidden:YES];

}];
}];
于 2013-10-31T18:59:47.713 回答