ios - 仅在单击按钮后显示事件指示器

标签 ios uiview uibutton activity-indicator

您好,我正在尝试通过单击按钮查看事件指示器。我试过了,但我遇到了一些问题。如果我将事件指示器拖到我的 Storyboard,但在运行我的应用程序时它是可见的,我想在单击按钮时显示。在我的应用程序中,我提供了照片上传选项。因此,如果他们单击上传按钮,我想查看事件指示器。 ..

这是我已经厌倦但无法正常工作的代码。

这是我的 h 文件,我在其中实现了事件指示器和按钮..

- (IBAction)click:(id)sender;
 @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *spinner;

这是我在我的 m 文件中使用的代码...

-(void)temp
{
 spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
 spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
 [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
 [self.view addSubview:spinner];
 [spinner startAnimating];
 [spinner release];
}

我在我的按钮中调用这个函数..

- (IBAction)click:(id)sender {
[self temp];
}

我还有一些其他问题,我看到了代码 here问题是

[yourView addSubview:spinner]; 

在你的 View 中,我给出了我的 uiviewcontroller 名称,但它给出的错误我已更改为

[self.view addSubview:spinner];

请告诉我我哪里做错了以及正确的方法是什么..谢谢

最佳答案

伙计,我遇到了问题...我认为您在白色 View 上添加了白色事件指示器,这就是它没有显示的原因,但它确实存在,所以...使用其他样式 UIActivityIndi​​catorViewStyleGray

-(void)temp
{
 spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
 spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
 [spinner setCenter:CGPointMake(480/2.0, 128.0/2)]; // (mid of screen) I do this because I'm in landscape mode
 [self.view addSubview:spinner];
 [spinner startAnimating];
 [spinner release];
}

关于ios - 仅在单击按钮后显示事件指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21900338/

相关文章:

ios - 未始终为 UIPageControl 触发 UIControlEventValueChanged 事件

ios - iOS 7 中未调用 UIViewControllerTransitioningDelegate 方法

iphone - 在 ViewController 类之外添加 UIView 类以显示 subview

ios - 选择时 View 从 UITableViewCell 中消失

iphone - 如何更改按钮的图像?

ios - 接收 subview 的触摸事件

ios - UITabBarController 的问题

objective-c - 将不同方向的 UIViewController 推送到上一个

ios - 在 FirstViewController 中单击按钮时如何在 SecondViewController 中显示图像

iphone - iOS 4 无法访问变量导致应用程序崩溃