从 ios 中的另一个视图禁用 UIview 元素
disable the UIview elements from another view in ios
我正在尝试禁用用户从一个视图到视图的交互。下面是我的代码。
DashboardViewControler.m
if([selectedTitle isEqual:@"VIEW"])
{
LatLongViewController * latview =[[LatLongViewController alloc]init];
latview.view.userInteractionEnabled = NO;
[self performSegueWithIdentifier:@"SWRevealViewController" sender:self];
}
在latview
中,我有UITextField
和UILabel
。我想在上述场景匹配时禁用用户交互。任何帮助将不胜感激。
假设您的 UIViewController
拥有相关视图作为属性:
yourTextfield.userInteractionEnabled = NO;
可在 here.
中找到来自 Storyboard
的如何连接视图 IBOutlet
的新手指南
要禁用所有子视图的用户交互,迭代它们:
for (UIView *view in [self.view subviews]) {
view.userInteractionEnabled = NO;
}
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;
。
我正在尝试禁用用户从一个视图到视图的交互。下面是我的代码。
DashboardViewControler.m
if([selectedTitle isEqual:@"VIEW"])
{
LatLongViewController * latview =[[LatLongViewController alloc]init];
latview.view.userInteractionEnabled = NO;
[self performSegueWithIdentifier:@"SWRevealViewController" sender:self];
}
在latview
中,我有UITextField
和UILabel
。我想在上述场景匹配时禁用用户交互。任何帮助将不胜感激。
假设您的 UIViewController
拥有相关视图作为属性:
yourTextfield.userInteractionEnabled = NO;
可在 here.
中找到来自Storyboard
的如何连接视图 IBOutlet
的新手指南
要禁用所有子视图的用户交互,迭代它们:
for (UIView *view in [self.view subviews]) {
view.userInteractionEnabled = NO;
}
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;
。