UITableView的子视图没有显示

时间:2014-01-23 04:33:34

标签: ios iphone uitableview subview

我有一个UITableViewController子类。当我尝试添加一个未显示的子视图时。

subView是一个UIImageView,我制作了一个自定义加载视图(当用户从​​web加载数据时显示)。

但是当我补充时,

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

微调器没有显示。我错过了什么或者我做错了什么?

修改

微调器代码

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];

3 个答案:

答案 0 :(得分:1)

使用MBProgress HUD 它是一个自定义控件,您可以通过它轻松添加各种类型的加载指示器

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];
}];

使用上面的代码或者还有很多其他选项

答案 1 :(得分:0)

尝试将其添加到tableView的contentView:

[self.tableVew.contentView addSubview:spinner];

答案 2 :(得分:0)

试试这个

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];