【发布时间】:2014-12-03 20:10:08
【问题描述】:
有什么办法可以做到,所以当按下 UIButton 时,它会在一行代码中添加一个子视图,即 init 是操作。无需调用 @selector 方法,然后调用该方法并且该方法添加子视图。
例如我尝试了以下两种尝试:
[theButton addTarget:self.view action:@selector(addSubview:theView) forControlEvents:UIControlEventTouchUpInside];
和
[theButton addTarget:self.view action:@selector(addSubview:) withObjects:theView forControlEvents:UIControlEventTouchUpInside];
但都失败了。
————
是我唯一的选择是调用一个方法然后添加视图,即
[theButton addTarget:self action:@selector(addTheSubview) forControlEvents:UIControlEventTouchUpInside];
-(void)addTheSubview {
[self.view addSubview:theSubview];
}
也许有一种方法可以通过在 UIButton 的addTarget 代码中使用块语句来实现这一点? (我对块语句知之甚少)。
【问题讨论】:
标签: ios objective-c uibutton selector objective-c-blocks