【问题标题】:How to get the choice selection to show up in a label in a new view controller如何让选项选择显示在新视图控制器的标签中
【发布时间】:2018-06-23 00:08:27
【问题描述】:

我想知道如何从选择器视图中选择一个选项,并让该选项出现在新的视图控制器中。例如,我想在下拉菜单中选择一个城市,并让该城市出现在新视图控制器的标签中。图片是我如何编码以创建选择器视图。 enter image description here

【问题讨论】:

标签: ios swift


【解决方案1】:

您可以使用带有样式操作表的 UIAlertCocntroller 来代替下拉菜单。将 ALertAction 放在 for 循环中,以使城市出现在列表中。只需单击按钮即可执行所有这些操作。

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];

for(NSString *str array){
    UIAlertAction *button = [UIAlertAction actionWithTitle:str style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self.button setTitle:str forState:UIControlStateNormal];
    }];
    [alert addAction:button];
}

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:cancel];

[self presentViewController:alert animated:YES completion:nil];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    相关资源
    最近更新 更多