Question

I have a UITableViewController subclass. When I try to add a subView its not showing.

The subView is a UIImageView, I made a custom loading view (its shown when user is loading data from web).

But when I add,

[self.tableView addSubview:spinner];
[spinner startAnimating];

The spinner is not showing. What am I missing or I did wrong?

EDIT

Code of spinner

UIImageView *spinner = [[UIImageView alloc]init];
spinner.animationImages = [NSArray arrayWithObjects:
                          [UIImage imageNamed:@"spin8.png"],
                          [UIImage imageNamed:@"spin7.png"],
                          [UIImage imageNamed:@"spin6.png"],
                          [UIImage imageNamed:@"spin5.png"],
                          [UIImage imageNamed:@"spin4.png"],
                          [UIImage imageNamed:@"spin3.png"],
                          [UIImage imageNamed:@"spin2.png"],
                          [UIImage imageNamed:@"spin1.png"],
                          nil];
Was it helpful?

Solution 2

Try this

CGRect spinnerFrame = //frame of spinner
UIImageView *spinner = [[UIImageView alloc] initWithFrame:spinnerFrame];
spinner.animationImages = [NSArray arrayWithObjects:
                      [UIImage imageNamed:@"spin8.png"],
                      [UIImage imageNamed:@"spin7.png"],
                      [UIImage imageNamed:@"spin6.png"],
                      [UIImage imageNamed:@"spin5.png"],
                      [UIImage imageNamed:@"spin4.png"],
                      [UIImage imageNamed:@"spin3.png"],
                      [UIImage imageNamed:@"spin2.png"],
                      [UIImage imageNamed:@"spin1.png"],
                      nil];

[self.tableView addSubview:spinner];
[spinner startAnimating];

OTHER TIPS

Use MBProgress HUD Its an custom control through which you can easily add various type of Loading indicator

MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeAnnularDeterminate;
hud.labelText = @"Loading";
[self doSomethingInBackgroundWithProgressCallback:^(float progress) {
hud.progress = progress;
} completionCallback:^{
[hud hide:YES];
}];

Use above code or there are lot of other options as well

Try adding it to the tableView's contentView:

[self.tableVew.contentView addSubview:spinner];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top