Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在同步过程中是否有关于UIActivityIndicatorView的解决方案?_Iphone_Objective C_Ipad_Uiactivityindicatorview - Fatal编程技术网

Iphone 在同步过程中是否有关于UIActivityIndicatorView的解决方案?

Iphone 在同步过程中是否有关于UIActivityIndicatorView的解决方案?,iphone,objective-c,ipad,uiactivityindicatorview,Iphone,Objective C,Ipad,Uiactivityindicatorview,在方法中,我启动UIActivityIndicatorView以启动。 然后使用NSXMLParser从XML中同步获取节点信息。 完成解析后,我希望停止UIActivityIndicatorView。 我的建议是在解析XML时显示UIActivityIndicatorView,但它不起作用。 有什么想法吗?谢谢 - (void)ButtonTouch{ [activityIndicator startAnimating]; /*get the login result*/ l

在方法中,我启动UIActivityIndicatorView以启动。 然后使用NSXMLParser从XML中同步获取节点信息。 完成解析后,我希望停止UIActivityIndicatorView。 我的建议是在解析XML时显示UIActivityIndicatorView,但它不起作用。 有什么想法吗?谢谢

- (void)ButtonTouch{

[activityIndicator startAnimating];
    /*get the login result*/
    loginXMLDealer *loginxmldealer = [[loginXMLDealer alloc] init];
    loginxmldealer.username = usernameField.text;
    loginxmldealer.password = passwordField.text;
    [loginxmldealer loginResult];
    [activityIndicator stopAnimating];
    if ([loginxmldealer.rspCode isEqualToString: @"0001"]) {

        UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Please check your passport." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [errorAlert show];
        [errorAlert release];
    }
    else {
        [self presentModalViewController:self.dataMainController animated:YES]; 

    }
    [loginxmldealer release];
}

你可以这样做:

- (void)buttonAction
{
  [activityIndicator startAnimating];
  [self performSelector:@selector(doWork) withObject:nil afterDelay:0.0];
}

- (void)doWork
{
  //Do your xml parsing here...
}

这使UI有机会在阻止主线程之前将控制权返回到runloop,从而进行更新。根据您的任务,最好使用后台线程或Grand Central Dispatch,这样UI的其余部分就不会阻塞,并且您可以给用户取消进程的选项(这在上述简单方法中是不可能的)。

向我们展示您已有的代码。然后,我们可以帮助您确定需要做什么/更改/添加/删除。好的。我已经编辑了我的问题。谢谢。要使动画正常工作,您必须在后台线程或GCD中进行处理。此代码将允许它出现,但不会设置动画。它将设置动画,因为UIActivityIndicator本身使用背景线程进行动画。