• <tfoot id='rWzA1'></tfoot>

    <small id='rWzA1'></small><noframes id='rWzA1'>

      <legend id='rWzA1'><style id='rWzA1'><dir id='rWzA1'><q id='rWzA1'></q></dir></style></legend>
        <bdo id='rWzA1'></bdo><ul id='rWzA1'></ul>

      <i id='rWzA1'><tr id='rWzA1'><dt id='rWzA1'><q id='rWzA1'><span id='rWzA1'><b id='rWzA1'><form id='rWzA1'><ins id='rWzA1'></ins><ul id='rWzA1'></ul><sub id='rWzA1'></sub></form><legend id='rWzA1'></legend><bdo id='rWzA1'><pre id='rWzA1'><center id='rWzA1'></center></pre></bdo></b><th id='rWzA1'></th></span></q></dt></tr></i><div id='rWzA1'><tfoot id='rWzA1'></tfoot><dl id='rWzA1'><fieldset id='rWzA1'></fieldset></dl></div>
      1. Iphone UIButton 在嵌套的 UIViews 中不起作用

        时间:2023-07-06
            <tbody id='TA6Z7'></tbody>
          • <i id='TA6Z7'><tr id='TA6Z7'><dt id='TA6Z7'><q id='TA6Z7'><span id='TA6Z7'><b id='TA6Z7'><form id='TA6Z7'><ins id='TA6Z7'></ins><ul id='TA6Z7'></ul><sub id='TA6Z7'></sub></form><legend id='TA6Z7'></legend><bdo id='TA6Z7'><pre id='TA6Z7'><center id='TA6Z7'></center></pre></bdo></b><th id='TA6Z7'></th></span></q></dt></tr></i><div id='TA6Z7'><tfoot id='TA6Z7'></tfoot><dl id='TA6Z7'><fieldset id='TA6Z7'></fieldset></dl></div>

            <legend id='TA6Z7'><style id='TA6Z7'><dir id='TA6Z7'><q id='TA6Z7'></q></dir></style></legend>

            <tfoot id='TA6Z7'></tfoot>
              <bdo id='TA6Z7'></bdo><ul id='TA6Z7'></ul>

            • <small id='TA6Z7'></small><noframes id='TA6Z7'>

                  本文介绍了Iphone UIButton 在嵌套的 UIViews 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我敢肯定,这该死的简单!我错过了一些东西,并且因为试图修复它而筋疲力尽.希望有人可以提供帮助.

                  This is so damn simple im sure! Im missing something and im exhausted from trying to fix it. hopefully someone can help.

                  CharacterView.m 中的按钮有效,但嵌套在 CharacterMale.m 中的按钮无效.我没有使用 IB,一切都是以编程方式完成的.什么会导致一个按钮工作而另一个按钮不工作?

                  The Button in CharacterView.m works but the button nested down in CharacterMale.m does not. I'm not using IB everything is done progmatically. What would cause one button to work and other not?

                  /////////////////////////////////////////////////////////////////////////////////
                   CharacterController.m
                  /////////////////////////////////////////////////////////////////////////////////
                  #import "CharacterController.h"
                  #import "CharacterView.h"
                  
                  @implementation CharacterController
                  
                  - (id)init {
                      NSLog(@"CharacterController init");
                      self = [ super init ];
                      if (self != nil) {
                      }
                      return self;
                  }
                  
                  - (void)loadView {
                      [ super loadView ];
                      characterView = [ [ CharacterView alloc ] init];
                      self.view = characterView;
                  }
                  
                  - (void)didReceiveMemoryWarning {
                      [super didReceiveMemoryWarning];
                  }
                  
                  
                  - (void)dealloc {
                      [super dealloc];
                  }
                  
                  @end
                  
                  /////////////////////////////////////////////////////////////////////////////////
                   CharacterView.m
                  /////////////////////////////////////////////////////////////////////////////////
                  
                  #import "CharacterView.h"
                  #import "CharacterMale.h"
                  
                  @implementation CharacterView
                  
                  - (id)initWithFrame:(CGRect)frame {
                      if (self = [super initWithFrame:frame]) {
                          characterMale = [ [ CharacterMale alloc ] init];
                          [self addSubview: characterMale];
                  
                          UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                          button.frame = CGRectMake(0, 200, 200, 100);
                          [button setImage:[UIImage imageNamed:@"btnCharSelect.png"] forState:UIControlStateNormal];
                          [button addTarget:self action:@selector(ApplyImage:) forControlEvents:UIControlEventTouchUpInside];
                          [ self addSubview: button ];
                      }
                      return self;
                  }
                  
                  - (void)drawRect:(CGRect)rect {
                  }
                  
                  -(void)ApplyImage:(id)sender
                  {
                      NSLog(@"CharacterView button works");
                  }
                  
                  - (void)dealloc {
                      [super dealloc];
                  }
                  
                  @end
                  
                  /////////////////////////////////////////////////////////////////////////////////
                   CharacterMale.m
                  /////////////////////////////////////////////////////////////////////////////////
                  
                  #import "CharacterMale.h"
                  #import "CharacterController.h"
                  
                  @implementation CharacterMale
                  
                  - (id)init {
                      self = [ super init];
                      if (self != nil) {
                          UIImage *image = [UIImage imageNamed:@"charMale.png"];
                          imageView = [[ UIImageView alloc] initWithImage:image];
                          [image release];
                          [ self addSubview: imageView ];
                  
                          UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                          button.frame = CGRectMake(0, 0, 200, 100);
                          [button setImage:[UIImage imageNamed:@"btnCharSelect.png"] forState:UIControlStateNormal];
                          [button addTarget:self action:@selector(ApplyImage:) forControlEvents:UIControlEventTouchUpInside];
                          [ self addSubview: button ];
                  
                      }
                      return self;
                  }
                  
                  -(void)ApplyImage:(id)sender
                  {
                      NSLog(@"CharacterMal button works");
                  }
                  
                  - (void)dealloc {
                      [super dealloc];
                  }
                  
                  @end
                  

                  推荐答案

                  终于!!!!!!

                  我必须使用 initWithFrame 初始化所有视图并传入有效的框架矩形.Init 应该与控制器一起使用,并且 initWithFrame 为 UIViews 传递矩形!!!!

                  I had to init all the views with initWithFrame and pass in valid frame rects. Init should be used with controllers and initWithFrame passing rects for UIViews!!!!

                  characterView = [ [ CharacterView alloc ] initWithFrame:CGRectMake(0, 0, 480, 320)]; 
                  then 
                  characterMale = [ [ CharacterMale alloc ] initWithFrame:frame];
                  

                  这篇关于Iphone UIButton 在嵌套的 UIViews 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Swift 中检查 UIButton 标题 下一篇:iPhone:覆盖 UIButton buttonWithType 以返回子类

                  相关文章

                    <legend id='2t2ug'><style id='2t2ug'><dir id='2t2ug'><q id='2t2ug'></q></dir></style></legend>
                  1. <i id='2t2ug'><tr id='2t2ug'><dt id='2t2ug'><q id='2t2ug'><span id='2t2ug'><b id='2t2ug'><form id='2t2ug'><ins id='2t2ug'></ins><ul id='2t2ug'></ul><sub id='2t2ug'></sub></form><legend id='2t2ug'></legend><bdo id='2t2ug'><pre id='2t2ug'><center id='2t2ug'></center></pre></bdo></b><th id='2t2ug'></th></span></q></dt></tr></i><div id='2t2ug'><tfoot id='2t2ug'></tfoot><dl id='2t2ug'><fieldset id='2t2ug'></fieldset></dl></div>
                      <bdo id='2t2ug'></bdo><ul id='2t2ug'></ul>
                      <tfoot id='2t2ug'></tfoot>

                      <small id='2t2ug'></small><noframes id='2t2ug'>