开发者

Adding an activityIndicator on modalViewController iphone

I'm trying to add an activityIndicator on a modalViewController.

Basically I want to start animating this activityIndicator after user presses a button on this modalViewController. But what's happening is whatever I'm doin开发者_StackOverflow社区g before firing presentModalViewController on this modalViewController is staying constant i.e. If I simply add activityIndicator and after presenting modalView, then even if I start it it doesn't show up. But if Before preseting this modalViewController if I fire [activity startAnimating]; then after presenting the modalView activity shows up animating.

So basically, I want to simply add the activityIndicator on modalViewController and start animating it after I press a button.

I'm using the following code:

  imageUploadView = [[UIViewController alloc]initWithNibName:nil bundle:nil]; 
  CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0);
  loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
  [loading sizeToFit];
   loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
    UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin |
    UIViewAutoresizingFlexibleBottomMargin);

   [imageUploadView.view addSubview:loading];
   [_picker_ presentModalViewController:imageUploadView animated:YES];

Can anybody please help?

Thanx in advance.


Inside your ViewController, in viewDidLoad or in ViewWillAppear try this:

  CGRect frame = CGRectMake(140.0, 410.0, 25.0, 25.0);
  loading = [[[UIActivityIndicatorView alloc] initWithFrame:frame] autoRelease];
  [loading sizeToFit];
  loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
  UIViewAutoresizingFlexibleRightMargin |
  UIViewAutoresizingFlexibleTopMargin |
  UIViewAutoresizingFlexibleBottomMargin);
  [self.view addSubView:loading];
  loading.startAnimateing


Add it as a subview.


I solved it by using below code

 activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

 // Set Center Position for ActivityIndicator

 activityIndicatorObject.center = CGPointMake(150, 250);
 activityIndicatorObject.backgroundColor=[UIColor grayColor];

 // Add ActivityIndicator to your view
 [self.view addSubview:activityIndicatorObject];

 activityIndicatorObject.hidesWhenStopped=NO;

 [activityIndicatorObject startAnimating];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜