UIActivityIndicatorView not displaying in UIAlertView - iOS7 [duplicate]

可紊 提交于 2019-12-10 16:37:32

问题


I need to UIActivityIndicatorView in UIAlertView when loading. But UIActivityIndicatorView is not displaying when I add this with UIActivityIndicatorView not displaying in UIAlertView - iOS7 in iOS 7. And this is working good in iOS 6 & lowest versions. Below is my code.

Is there any solution ? . thanks.

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:nil message:@"\n\n\n\nloading.." delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil];
[alertView show];

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame= CGRectMake(50, 10, 37, 37);
activityIndicator.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;

[alertView addSubview:activityIndicator];

[activityIndicator startAnimating];

回答1:


Apple deprecated addSubview method in case of UIAlertView. So you can't add any subviews any more to AlertView, for example : activity indicator or some progress bar.

Here you can look at my question where people share custom Alerts which will support adding controls

UIAlertView addSubview in iOS7




回答2:


You can not do customization with UIAlertView

Read this documentation

Best way is create custom UIView which look/feature like UIAlertView and add your activity indicator on this view.



来源:https://stackoverflow.com/questions/18981040/uiactivityindicatorview-not-displaying-in-uialertview-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!