【问题标题】:in code not working properly of image view and button?在图像视图和按钮的代码中无法正常工作?
【发布时间】:2015-07-03 05:43:50
【问题描述】:

我可以使用 imageview 和按钮。如果 imageview 为 null 或 未选中然后按钮被设置为禁用并像这样打印消息 @“选择图像”..但在我的代码中不起作用.. 图像视图不允许空值。这段代码有什么错误。 给我建议谢谢...

     -(void)viewDidLoad 

 {
   [super viewDidLoad];
      if(self.imageview == null) // imageview_outlet
      Btn.enabled=yes;//button_outlate
         NSLog(@"select image in imageview");
      }
         else
      Btn.enables=no;//button outlet
     }
          }

【问题讨论】:

  • if(self.imageview.image == null) 并尝试
  • 嘿您的问题存在或结束

标签: objective-c xcode null uiimageview uibutton


【解决方案1】:

解决方案 1:

if(imageview.image == nil)
{// imageview_outlet
    Btn.enabled=YES;//button_outlate
    NSLog(@"select image in imageview");
}
else
{
    Btn.enabled=NO;//button outlet
}

我认为最好的解决方案是使用标签。

//somewhere when you select or add the image you change the imageview tag 2
imageview.tag =2;


imageview.tag =1; //bydefault set tag 1



if(imageview.tag == 1)
{// imageview_outlet
    Btn.enabled=YES;//button_outlate
    NSLog(@"select image in imageview");
}
else
{
    Btn.enabled=NO;//button outlet
}

【讨论】:

  • imageview 他提到 // imageview_outlet 并且你的想法是他需要设置 tag =1 ,imageview 对象总是存在于视图中,所以我认为这是不正确的
  • 我想我们也将标签设置为故事板中的图像视图。
  • 显然,但在您此刻的问题和答案之间没有太大区别
猜你喜欢
  • 1970-01-01
  • 2017-03-29
  • 2014-12-20
  • 1970-01-01
  • 1970-01-01
  • 2020-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多