[tableView reloadData]; doesn't work until I scroll the tableView

后端 未结 5 1963
南方客
南方客 2021-02-01 18:57

I have a simple app that downloads search results in XML when the user types in a UISearchBar. The download+parsing is threaded and once done it fires an NSNo

5条回答
  •  鱼传尺愫
    2021-02-01 19:50

    I have the same problem, and I have tried all the solution I can find on google. But All of them don't work.

    At last I found that I add observer before viewDidLoad, and then [self.tableView reloadData] is not working.

    First I call the setObserverForUserInfoDatabase in the viewDidLoad of my root navigation view controller. Because I think it was called earlier. The function is like this:

    - (void)setObserverForUserInfoDatabase:(NSString *)name {
        [[NSNotificationCenter defaultCenter] addObserverForName:name
                                                          object:nil
                                                           queue:nil
                                                      usingBlock:^(NSNotification *note) {
                                                          [self loadUserInfo];
                                                          [self.tableView reloadData];
                                                          NSLog(@"User Panel Notification \n %@", self);
                                                      }];}
    

    Then I move the code into viewDidLoad of the viewController itself.

    - (void)viewDidLoad {
        NSLog(@"View Did Load");
        [super viewDidLoad];
    
        [self setObserverForUserInfoDatabase:UserInfoDataBaseAvailabilityNotification];
    }
    

    And then everything works fine.

    I don't know the reason yet. If anyone knows please tell me.

提交回复
热议问题