Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何将UIImageView添加到UIView(而不是UIViewController)?_Objective C_Ipad_Uiview_Uiimageview - Fatal编程技术网

Objective c 如何将UIImageView添加到UIView(而不是UIViewController)?

Objective c 如何将UIImageView添加到UIView(而不是UIViewController)?,objective-c,ipad,uiview,uiimageview,Objective C,Ipad,Uiview,Uiimageview,我创建了基于视图的应用程序。 我有一个SampleGameViewController.xib,它包含主视图和与类行为相关的子视图 SampleViewController.xib: 看法 查看如果你想在简单UIView上添加一个图像视图,那么只需执行[self.View addSubview:imageview]如果您是从行为类方法获取该图像,则从该方法返回UIImageView并将其添加到视图中 试试这个: Behavior *b = [[Behavior alloc] init];

我创建了基于视图的应用程序。 我有一个SampleGameViewController.xib,它包含主视图和与类行为相关的子视图

SampleViewController.xib:

  • 看法

    • 查看如果你想在简单UIView上添加一个图像视图,那么只需执行
      [self.View addSubview:imageview]如果您是从行为类方法获取该图像,则从该方法返回UIImageView并将其添加到视图中
      试试这个:

      Behavior *b = [[Behavior alloc] init];
      
      然后在行为类中编写一个方法

      -(UIImageView*) initilizeWithType:(NSString *)type position:(CGRect) pos mapArray:(NSMutableArray *) mapArr {
      // Your Logic
      
      return  imgView;  //UIImageView object
      } 
      
      然后在viewcontroller中调用此方法作为

      UIImageView *imgView=[b initilizeWithType:@"YOUR STRING" position:YOUR RECT pos mapArray:YOUR ARRAY ];
      

      此行将您的imageView帧指定给。。。据我所知什么都没有。这应该是
      pos
      还是
      rectForDraw
      ?在drawRect中添加到视图时,您显式地设置了一个真实帧,因此这可能就是区别所在

      消息:“在“Behavior*”类型的对象上找不到属性“view”,使行为成为UIView的子类。或者您可以将方法的返回类型(在行为中)设置为UIImageView,或者只需执行
      [self addSubView:imageView]
      -(id)initilizeWithType:(NSString*)类型位置:(CGRect)pos mapArray:(NSMutableArray*)mapArr{UIImageView*imgg;…return imgg;}
      无法正常工作,正如我已经编写的那样,
      [self addSubView:imageView]
      也不起作用..将返回类型设置为“-(UIImageView*)initilizeWithType:(NSString*)类型位置:(CGRect)pos mapArray:(NSMutableArray*)mapArr{UIImageView*imgg;…return imgg;}我有错误。例如,我写了它。即使我写了'imgg.frame=CGRectmake(100,100,100),图像没有出现。您能否澄清以下几点:在viewcontroller中创建了
      b
      之后,您如何处理它?您在上一个代码段中覆盖了哪个
      drawRect
      ?这是
      行为
      类吗?我创建了一个类实例来管理每个类。类绘制图像并将其移入自己的逻辑。因此,创建了一个实例数组,每个实例负责移动图像。>>您在上一个代码段中覆盖了哪个drawRect?这是Behavior类吗?是的,在Behavior类中。但它只是一个示例,但是
      b
      在某个时候会被添加为视图控制器视图的子视图吗?您能显示实际值吗您正在使用的l代码?一切正常)您可以在那里看到我的代码示例:
      Behavior *b = [[Behavior alloc] init];
      
      -(UIImageView*) initilizeWithType:(NSString *)type position:(CGRect) pos mapArray:(NSMutableArray *) mapArr {
      // Your Logic
      
      return  imgView;  //UIImageView object
      } 
      
      UIImageView *imgView=[b initilizeWithType:@"YOUR STRING" position:YOUR RECT pos mapArray:YOUR ARRAY ];
      
      imgg.frame = rect;