【问题标题】:how to add a UITableView into UIAlertView in iOS 7如何在 iOS 7 中将 UITableView 添加到 UIAlertView
【发布时间】:2013-10-07 03:04:13
【问题描述】:

通过谷歌搜索发现 iOS 7 不再支持子视图。

有些人建议创建自定义视图,但我不知道该怎么做。

这是我的代码,谁能指出正确的方向?

-(IBAction)click_select_fruit_type
{
select_dialog = [[[UIAlertView alloc] init] retain];
[select_dialog setDelegate:self];
[select_dialog setTitle:@"Fruit Type"];
[select_dialog setMessage:@"\n\n\n\n"];
[select_dialog addButtonWithTitle:@"Cancel"];

idType_table = [[UITableView alloc]initWithFrame:CGRectMake(20, 45, 245, 90)];
idType_table.delegate = self;
idType_table.dataSource = self;
[select_dialog addSubview:idType_table];

[idType_table reloadData];

[select_dialog show];
[select_dialog release];

}

【问题讨论】:

    标签: uitableview ios7 uialertview


    【解决方案1】:

    您可以在 iOS7 的标准警报视图中将 accessoryView 更改为任何自己的 customContentView

    [alertView setValue:customContentView forKey:@"accessoryView"];
    

    请注意,您必须在 [alertView show] 之前调用它。

    最简单的示例:

    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"TEST" message:@"subview" delegate:nil cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
    v.backgroundColor = [UIColor yellowColor];
    [av setValue:v forKey:@"accessoryView"];
    [av show];
    

    真正的tableView作为UIAlertView的子视图示例:

    【讨论】:

    • 非常好的解决方案。看起来很老套,但比试图找到 UIAlertview 替代品来添加子视图更好。
    【解决方案2】:

    你不能。 Apple 弃用了在 iOS 7 中向UIAlertView 添加任何子视图的功能。我认为这是一个不错的决定。很多人辱骂UIAlertView

    创建自定义视图是个好主意,但这不是您在代码中编写的内容。看来您又要向UIAlertView 添加子视图了。

    Alert View UI guide here

    【讨论】:

    • 感谢链接,我看到有个东西叫 UIActionSheet developer.apple.com/library/ios/documentation/UserExperience/… 看起来很有趣
    • 是的,这也是人们正在使用的一种解决方案。但是,如果您将 UIViewController 子类化以模仿 UIAlertView,这也不是一个坏主意。环顾 Github,看看是否有人做过。
    【解决方案3】:

    你必须继承 UIViewController 并使用它的 preferredContentSize 属性来做一些模仿 UIAlertView 布局的“自定义模式”

    【讨论】:

      猜你喜欢
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 1970-01-01
      • 2011-07-13
      • 2012-03-05
      • 1970-01-01
      相关资源
      最近更新 更多