简体   繁体   English

如何在用户在ios中查看视图之前加载数据?

[英]how to load data , before user see the view in ios?

In my case i have two views in tab bar controller (categories and Home), one with collection view and one with table view. 就我而言,我在标签栏控制器中有两个视图(类别和主页),一个具有集合视图,一个具有表视图。 In the table view, It starts to load data when only user taps(Home) on its tab bar item.I want to load data , when app launch. 在表格视图中,仅当用户点击其选项卡栏项上的(主页)时它才开始加载数据。我想在应用启动时加载数据。 I am using AFNetworking , and I have called to my data loading method in viewDidLoad. 我正在使用AFNetworking ,并且已经在viewDidLoad中调用了我的数据加载方法。 same thing happen with collection view.please help me with this.hope your help thank you. 集合视图也会发生同样的事情。请为此提供帮助。希望您的帮助谢谢。 I have attached part of my code, which I used to load data to table view. 我已经附加了部分代码,该代码曾用于将数据加载到表视图中。

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view addSubview:self.homeTableView];
//    [self homeviewData];

    SWRevealViewController *revealController = self.revealViewController;
    if (revealController) {
        [self.sidebarButton setTarget:self.revealViewController];
        [self.sidebarButton setAction:@selector(revealToggle:)];
        [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
    }
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated
{
    [self homeTableView];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)homeviewData
{
    homepost = nil;
    NSString *mogohomeWebserviceUrl = [NSString stringWithFormat:@"some url"];
    AFHTTPRequestOperationManager *homeManager = [AFHTTPRequestOperationManager manager];
    [homeManager GET:mogohomeWebserviceUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        homeposts = (NSDictionary *)responseObject;
        homepost = [NSMutableArray array];
        NSArray *results = [homeposts objectForKey:@"posts"];
        for (NSDictionary *all in results)
        {
            Home *sweetHome = [Home new];
            sweetHome.homeImage = [NSString stringWithFormat:@"%@", [all objectForKey:@"thumbnail"]];
            sweetHome.homeTitle = [NSString stringWithFormat:@"%@", [all objectForKey:@"title"]];
            sweetHome.homewebUrl = [NSString stringWithFormat:@"%@", [all objectForKey:@"url"]];
            sweetHome.modifiedTime = [NSString stringWithFormat:@"%@", [all objectForKey:@"modified"]];

            [homepost addObject:sweetHome];
            [self.homeTableView reloadData];

        }

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [homepost count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"homereuseIdentifier"];
    Home *mogoHome = [homepost objectAtIndex:indexPath.row];

    NSString *homeimageurlname = [NSString stringWithFormat:@"%@", mogoHome.homeImage];
    NSURL *homeimageurl = [NSURL URLWithString:homeimageurlname];

    cell.hometitleLabel.text = mogoHome.homeTitle;
    [cell.homeimageView setImageWithURL:homeimageurl placeholderImage:nil];
    cell.timeLabel.text = [[mogoHome.modifiedTime componentsSeparatedByString:@" "] objectAtIndex:1];
    return cell;
}

You got to understand that the data will only be loaded and displayed after the API request to fetch the data is completed... 您已经了解到,仅在获取数据的API请求完成后才会加载和显示数据...

This implies you should either be ready with data before the screen appears. 这意味着在屏幕出现之前您应该已经准备好数据。 This is possible only if the data is independent of user action or Master Data, and you can fetch it right at App Launch. 仅当数据与用户操作或主数据无关时,才有可能,并且您可以在应用启动时直接获取数据。 If user action is responsible for the fetched data, you have no option but to wait, and show an Activity Indicator. 如果用户操作负责提取的数据,则别无选择,只能等待,并显示活动指示器。 If you decide to do this, you will find a relevant answers how to do that.. 如果您决定执行此操作,则会找到相关的答案。

All the best... 祝一切顺利...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在用户看到表格之前在表格视图中显示它 - Displaying an array in a table view before the user see it iOS如何在用户看到视图之前实现倒计时屏幕 - iOS How to implement a countdown screen before the user sees the view 如何在iOS 9中加载第二个视图,可以看到第一个视图(透明) - How to load second view ,that can see the first view thourgh it (transparent), in ios 9 如何在iOS中加载查看然后加载数据? - How do I load view THEN load data in iOS? 如何在没有用户能够看到呈现视图的情况下使用模态视图控制器启动iOS应用程序? - How to start an iOS app with a modal view controller already presented without the user being able to see the presenting view? 在iOS中离开视图之前要求用户确认 - Asking for user confirmation before leaving a view in iOS TabBar应用程序-在显示视图之前加载数据 - TabBar app - load data before showing view iOS UI - 如何告诉用户表格视图中没有数据? - iOS UI - how to tell user that there are no data in table view? 在 iOS 中显示给用户之前修改通知数据 - Modify Notification data before displaying to user in iOS 如何在iOS之前检查用户是否已经看过推送通知权限警报视图? - How to check whether user has seen the push notification permissions alert view before in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM