繁体   English   中英

iOS活动指示器问题

[英]iOS activity indicator issue

我在子视图中创建了一个UITableview 对于填充表我使用一些jsonget请求。 在此过程中,我想显示一个活动指标。 我不知道为什么它没有显示。

示例代码:

activityIndicator1 = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityIndicator1.center = CGPointMake([[UIScreen mainScreen]bounds].size.width/2, [[UIScreen mainScreen]bounds].size.height/3);
[self.window addSubview:activityIndicator1];
activityIndicator1.color=[UIColor greenColor];
[self bringSubviewToFront:activityIndicator1];
[UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

[activityIndicator1 startAnimating];

问题是活动指示器未显示。

谢谢并恭祝安康

维卡斯

您需要在子视图中添加activityIndi​​cator1

[self.subView addSubView: activityIndicator1];

activityIndi​​cator1的中心应该是您的子视图中心。

activityIndicator1.center = subView.center;

希望这可以帮助。

谢谢

在.h文件中添加此内容,

@property(nonatomic, retain) UIActivityIndicatorView *indicator;

而不是在按钮单击方法中添加此代码,

indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        indicator.frame = CGRectMake(0.0, 0.0, 60.0, 60.0);
        indicator.color = [UIColor colorWithRed:0.949 green:0.571 blue:0.558 alpha:1.000];
        [indicator setBackgroundColor:[UIColor colorWithRed:1 green:1.000 blue:1 alpha:1.000]];
        indicator.center = self.view.center;
        [self.view addSubview:indicator];
        [indicator bringSubviewToFront:self.view];
        [UIApplication sharedApplication].networkActivityIndicatorVisible = TRUE;

        [indicator startAnimating];

比你想要使用的停止指示器,

[indicator stopAnimating];

希望这会帮助你。

UIActivityIndi​​cator的hidesWhenStopped属性默认为YES。 此外,它默认停止。 所以你的活动指标就是隐藏的。 添加此代码:

activityIndicator1.hidden = NO;

当您使用来自api请求的新数据刷新表时,一个常用且方便的工具是UIRefreshControl ,当用户拉出表刷新时,它将显示为ActivityIndi​​cator旋转,同时调用以获取新数据。

@property (strong, nonatomic)  UIRefreshControl   *refreshControl;

然后在viewDidLoad创建refreshControl并添加目标操作

-(void)viewDidLoad{

   [super viewDidLoad]

    self.refreshControl = [[UIRefreshControl alloc]init];
   [self.refreshControl addTarget:self action:@selector(refreshTable) forControlEvents:UIControlEventValueChanged];
   [yourTableView addSubview:self.refreshControl];
}

通过向下拉动桌子,活动指示器将显示,并且将进行刷新表格的调用。

-(void)refreshTable{
   // Here your call to pull data from your API to refresh the data
   // ** Your code here to pull in your JSON data and update your datasource **
   //Once the data has been retrieved or failed to retrieve, call this to end the refreshing

   [self.refreshControl endRefreshing];
 }

如果这是你想要重新创建的,我希望这会有所帮助。

注意 - 当然,用户需要向下拉动拉动 - 刷新 ”动作来激活它

这样做

UIView*  WaitingView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height)];
WaitingView.backgroundColor=[UIColor blackColor];
WaitingView.alpha=0.5;
 UIActivityIndicatorView*   activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
                    UIActivityIndicatorViewStyleWhiteLarge ];
    [activityView setCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)];
    [activityView setContentMode:UIViewContentModeCenter];

[WaitingView addSubview:activityView];
[self.view addSubview:WaitingView];
[activityView startAnimating];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM