سؤال

I have View with TableView, I want to show activity indicator when I do something but he don't show, I found this code:

UIActivityIndicatorView *activityView =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityView.frame = CGRectMake(120, 230, 50, 50);
[self.ReportTableView addSubview:activityView];

[activityView startAnimating];

No errors but and now indicator show.

Solution:

[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activityView];
هل كانت مفيدة؟

المحلول

if your tableview backgrond color is white then it will not show because UIActivityIndicatorViewStyleWhite is also white

[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

Change to

[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

نصائح أخرى

Dont add activity inside the tableview.Add it in the main view or the superview of table

Dont forget to update the frame accordingly to where you add it

[self.ReportTableView.superView addSubview:activityView];
[self.ReportTableView.superView bringSubviewToFront:activityView];
// Your code
[activityView startAnimating];

[self.ReportTableView addSubview:activityView];

Move [activityView startAnimating]; after

[self.ReportTableView addSubview:activityView];

Order is very important

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top