0

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];
Rashad
  • 11,057
  • 4
  • 45
  • 73

3 Answers3

1

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

bhavya kothari
  • 7,484
  • 4
  • 27
  • 53
0

Try adding it to the tableView's contentView:

[self.tableVew.contentView addSubview:spinner];
Buntylm
  • 7,345
  • 1
  • 31
  • 51
Paul Dardeau
  • 2,589
  • 1
  • 13
  • 10
0

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];
Akhilrajtr
  • 5,170
  • 3
  • 19
  • 30
  • >> Your solution worked but can you tell the reason why it didn't work in tableView subclass? It is working fine in viewController subclass. – Rashad Jan 23 '14 at 06:24
  • in viewController subclass, you used `initWithImage:` or `init`.? Because setting the image property does not change the size of a UIImageView, but `initWithImage:` does see [here](https://developer.apple.com/library/ios/documentation/uikit/reference/UIImageView_Class/Reference/Reference.html#jumpTo_9). And are you sure not setting any frame to `UIImageView` in viewController subclass.? – Akhilrajtr Jan 23 '14 at 08:57
  • Yes I am sure. In my viewController i used "spinner = [[UIImageView alloc]init];" – Rashad Jan 23 '14 at 09:38