Activity indicator (spinner) with UIActivityIndicatorView

前端 未结 4 534
耶瑟儿~
耶瑟儿~ 2021-02-04 21:32

I have a tableView that loads an XML feed as follows:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    if ([stories count] == 0) {         


        
4条回答
  •  情歌与酒
    2021-02-04 22:18

    In Cocoa (and most other app frameworks) the user interface is updated by the main thread. When you manipulate views, they are typically not redrawn until control returns to the run loop and the screen is updated.

    Because you are parsing the XML in the main thread, you are not allowing the screen to update, and that is why your activity indicator is not appearing.

    You should be able to fix it by doing the following:

    1. In viewDidAppear, show/animate the spinner and then call

      [self performSelector:@selector(myXMLParsingMethod) withObject:nil afterDelay:0];

    2. In myXMLParsingMethod, parse your XML, then hide/stop the spinner.

    This way, control will return to the run loop before parsing begins, to allow the spinner to begin animating.

提交回复
热议问题