【问题标题】:disable the UIview elements from another view in ios从 ios 中的另一个视图禁用 UIview 元素
【发布时间】:2016-11-01 13:01:27
【问题描述】:

我正在尝试禁用用户从一个视图到视图的交互。下面是我的代码。

DashboardViewControler.m

  if([selectedTitle isEqual:@"VIEW"])
  {
     LatLongViewController * latview =[[LatLongViewController alloc]init];
     latview.view.userInteractionEnabled = NO;  
     [self performSegueWithIdentifier:@"SWRevealViewController" sender:self];
  }

latview 中,我有UITextFieldUILabel。我想在上述场景匹配时禁用用户交互。任何帮助将不胜感激。

【问题讨论】:

  • 为什么不禁用文本字段,这样用户在禁用后就无法访问它们。否则,您可以将 latView 设置为隐藏。

标签: ios objective-c uiview user-interaction


【解决方案1】:
latview.view.userInteractionEnabled = NO; 

IBOutlet 无法做到这一点。所有IBOutlet 都是 由ViewController 操作。这是我的解决方案:

-在LatLongViewController.h文件中创建新的BOOL

@property BOOL editMode; 

-在 DashboardViewControler.m

  if([selectedTitle isEqual:@"VIEW"])
  {
     LatLongViewController * latview =[[LatLongViewController alloc]init];
     latview.editMode = NO;
     [self performSegueWithIdentifier:@"SWRevealViewController" sender:self];
  }

-在 LatLongViewController.m

    - (void)viewDidLoad {
       if(_editMode == NO){
          view.userInteractionEnabled = NO;
       }
    }

如果您在此视图中只有一个UITextField,我认为您应该使用textfield.enable = NO;

【讨论】:

    【解决方案2】:

    假设您的UIViewController 拥有相关视图作为属性:

    yourTextfield.userInteractionEnabled = NO;
    

    初学者指南如何从Storyboard 连接视图IBOutlet 可以找到here

    要禁用所有子视图的用户交互,请对其进行迭代:

    for (UIView *view in [self.view subviews]) {
        view.userInteractionEnabled = NO;
    }
    

    【讨论】:

    • 是否可以禁用 UIview 中的所有元素?
    • 相应地更新了答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多