【问题标题】:UITableView's subview not showingUITableView 的子视图不显示
【发布时间】:2014-01-23 04:33:33
【问题描述】:

我有一个 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];

【问题讨论】:

  • 请输入spiner的代码
  • 尝试在你的代码中实现这个stackoverflow.com/questions/20837787/…
  • frame设置为spinner
  • UIImageView设置框架
  • 我认为这不是问题所在。因为我在其他子类 UIViewController 中使用了相同的代码。它没有显示在 UITableViewController 的子类中。无法理解问题所在。

标签: ios iphone uitableview subview


【解决方案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];
}];

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

【讨论】:

    【解决方案2】:

    试试这个

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

    【讨论】:

    • >> 您的解决方案有效,但您能说出它在 tableView 子类中无效的原因吗?它在 viewController 子类中工作正常。
    • 在 viewController 子类中,您使用了initWithImage:init。?因为设置 image 属性不会改变 UIImageView 的大小,但是initWithImage: 确实看到了here。你确定没有在 viewController 子类中为UIImageView 设置任何框架吗?
    • 是的,我确定。在我的视图控制器中,我使用了“spinner = [[UIImageView alloc]init];”
    【解决方案3】:

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

    [self.tableVew.contentView addSubview:spinner];
    

    【讨论】:

    • 对不起,我的错误——我在想表格视图的单元格。对不起!
    • 我没有尝试将 sub 添加到 tableViewCell 我尝试在从 web 加载数据时将 subView 添加到 tableView。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-06-03
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多