有没有什么办法可以使它在按下UIButton时,它只是在init行为的一行代码中添加子视图。无需调用@selector方法,然后调用该方法,该方法添加一个子视图。直接从UIButton动作添加子视图,无需调用方法
例如我尝试以下两种尝试:
[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
? (我对块语句知之甚少)。