【问题标题】:Action for dynamically created UIButton inside UITextViewUITextView 内动态创建的 UIButton 的操作
【发布时间】:2010-06-02 18:37:22
【问题描述】:

我有一个滚动视图;在里面我添加了一个或多个文本视图;我在每个文本视图中添加一个按钮:

UIScrollView UITextView 用户界面按钮 UITextView 用户界面按钮 ...

这是代码的一部分:

- (void)viewDidLoad { ... [self loadUI]; ... } -(void) loadUI { UITextView *textView; ... for (...) { UIButton *editButton = [[UIButton alloc] initWithFrame: CGRectMake(self.scrollView.frame.size.width - 230, 0, 50, 20)]; ... [editButton addTarget:self action:@selector(editPressed:) forControlEvents:UIControlEventTouchUpInside]; ... textView = [[CustomTextView alloc] initWithFrame: CGRectMake(10, dynamicHeight, self.queuedView.frame.size.width - 100, 500)]; textView.userInteractionEnabled = NO; ... [textView addSubview:editButton]; [editButton release]; ... [self.scrollView addSubview:textView]; [textView release]; } } - (IBAction) editPressed:(id)sender { ... }

由于某种原因,当我按下按钮时不会调用 editPressed 方法。任何想法为什么?我尝试将为文本视图启用的交互设置为“是”,但仍然没有。我将形式 (IBAction) 更改为 (void),仍然没有。

谢谢你, 米海

【问题讨论】:

    标签: iphone uiscrollview uibutton uitextview


    【解决方案1】:

    显然,textView.userInteractionEnabled = YES; 成功了。我以前试过这个,但没有奏效。也许我必须在更改后进行干净的构建。

    【讨论】:

      【解决方案2】:

      尝试将按钮添加到文本字段的右视图

      textField.rightView = editButton 而不是[textView addSubview:editButton];

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-13
        • 1970-01-01
        • 1970-01-01
        • 2021-11-03
        • 1970-01-01
        相关资源
        最近更新 更多