ViewController 之间的 UIActivityIndi​​catorView

发布于 2024-12-21 13:04:58 字数 382 浏览 2 评论 0原文

在我的 FirstViewController 中,有一个调用 SecondViewController 的 IBAction。

ViewDidLoad 中的 SecondViewController 从服务器加载一个数组,因此 FirtsViewControllerSecondViewController 之间的转换时间这么长。

我想在 FirstViewController 中放置一个 UIActivityIndi​​catorView ,当 IBAction y 按下时它将产生动画,并在视图之间的转换完成时停止。

¿一些想法?

谢谢大家。

此致

In my FirstViewController, there is an IBAction that call to SecondViewController.

SecondViewController in his ViewDidLoad loads an array from an server, for this reason the time of transition between FirtsViewController and SecondViewController is so long.

I would like put an UIActivityIndicatorView in FirstViewController that it will animating when IBAction y push, and stop when the transition between views is finish.

¿Some idea?

Thanks for all.

Best regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

恍梦境° 2024-12-28 13:04:58

您应该异步加载数据。像这样的东西:

// second view controller
- (void)viewDidLoad
{
    // show loading activity (e.g. UIActivityIndicatorView)

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self loadDataFromServer];
        dispatch_async(dispatch_get_main_queue(), ^{
            // hide loading activity and refresh view with loaded data
        });
    );
}

You should load the data asynchronously. Something like:

// second view controller
- (void)viewDidLoad
{
    // show loading activity (e.g. UIActivityIndicatorView)

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        [self loadDataFromServer];
        dispatch_async(dispatch_get_main_queue(), ^{
            // hide loading activity and refresh view with loaded data
        });
    );
}
一向肩并 2024-12-28 13:04:58

为此,您必须在第一个视图控制器或第二个视图控制器上添加活动指示器。

或者另一个选择是放置一个计时器来加载第二个视图控制器,如下所示,

-(void)viewDidLoad    
{       
    timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(firstAPICall) userInfo:nil repeats:NO];    
}

从上面的代码行,屏幕将立即导航,然后从服务器加载数据。使用“firstAPIcall”方法。

For that you have to add activity indicator either on the firstViewController or on the secondViewController.

Or Another option is put a timer to load second view controller like this,

-(void)viewDidLoad    
{       
    timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(firstAPICall) userInfo:nil repeats:NO];    
}

From the above line of code the screen will immediately navigate and and then load the data from server. Using the "firstAPIcall" method.

树深时见影 2024-12-28 13:04:58

在单独的方法中编写服务器调用。在第二个视图控制器的 viewDidLoad 中,在后台线程上调用此服务器方法。并开始显示带有活动指示器的视图。同时,在服务器方法中,一旦调用完成,就调用主线程上的回调方法,该方法隐藏活动指示器并在第二个视图控制器上显示所需的内容。

Write the server call in a separate method. In the viewDidLoad of your second View controller, call this server method on the background thread. And start showing a view with an activity indicator. Meanwhile in the server method, once the call is complete, make a call to a callback method on the main thread which hides the activity indicator and display the required things on your second view controller.

岁吢 2024-12-28 13:04:58

我建议将带有活动指示器的总体视图放在所有视图之上,这样无论呈现哪个视图,都将始终呈现活动指示器。
为此,您需要创建一个带有活动指示器的透明视图,您可以在此处阅读相关内容:
http://ramin.firoozye。 com/2009/09/29/semi-modal-transparent-dialogs-on-the-iphone/

I would recommend to put an overall view with activity indicator, above all the views so no matter which view is being presented the activity indicator will always be presented.
To do so, you need to create an transparent view with activity indicator, you can read about that here:
http://ramin.firoozye.com/2009/09/29/semi-modal-transparent-dialogs-on-the-iphone/

自此以后,行同陌路 2024-12-28 13:04:58

你可以这样做:

SecondViewController 的 viewDidLoad

.h 文件上的

@interface SecondViewController 
{
    UIActivityIndicatorView *activityView;
}

@property (nonatomic, retain) UIActivityIndicatorView *activityView;

@end

在.m 文件中的

@synthesize activityView;

- (void) viewDidLoad
{
    self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 80, 30, 30)];
           self.activityView.hidesWhenStopped = YES ;
    [self addSubview:activityView];
    activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [activityView startAnimating];

    [self performSelector:@selector(getData) withObject:nil afterDelay:0.1];

}

- (void) getData
{
   // code for server call
   .
   .
   // as downloading get complited

    [self.activityView stopAnimating]
}

you can do like this :

In your SecondViewController's viewDidLoad

on .h file

@interface SecondViewController 
{
    UIActivityIndicatorView *activityView;
}

@property (nonatomic, retain) UIActivityIndicatorView *activityView;

@end

in .m file

@synthesize activityView;

- (void) viewDidLoad
{
    self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 80, 30, 30)];
           self.activityView.hidesWhenStopped = YES ;
    [self addSubview:activityView];
    activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [activityView startAnimating];

    [self performSelector:@selector(getData) withObject:nil afterDelay:0.1];

}

- (void) getData
{
   // code for server call
   .
   .
   // as downloading get complited

    [self.activityView stopAnimating]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文