简体   繁体   English

UITableView的子视图未显示

[英]UITableView's subview not showing

I have a UITableViewController subclass. 我有一个UITableViewController子类。 When I try to add a subView its not showing. 当我尝试添加subView时,它没有显示。

The subView is a UIImageView, I made a custom loading view (its shown when user is loading data from web). subView是一个UIImageView,我创建了一个自定义加载视图(当用户从​​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];

Use MBProgress HUD Its an custom control through which you can easily add various type of Loading indicator 使用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];
}];

Use above code or there are lot of other options as well 使用上面的代码,或者还有很多其他选项

尝试将其添加到tableView的contentView中:

[self.tableVew.contentView addSubview:spinner];

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

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

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