我有一个名为 FirstController 的 ViewController,它有 3 个按钮,每次触摸其中一个按钮时,它都会打开 SecondController(我的另一个 ViewController)。但即使所有三个按钮都打开同一个 ViewController,我也不希望该 ViewController 完全相同,但它会包含不同的对象,具体取决于按下的按钮。我在 SecondController 中有一个 ScrollView,我想根据按下的按钮将不同的图像作为 subview 添加到 ScrollView 中。
这是我到目前为止得到的:
<小时/>#import "FirstController.h"
#import "SecondController.h"
@interface Level1 ()
@end
@implementation FirstController
- (IBAction) button1 {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SecondController *ViewForButton1 = [mainStoryboard instantiateViewControllerWithIdentifier:@"View2"];
}
- (IBAction) button2 {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SecondController *ViewForButton2 = [mainStoryboard instantiateViewControllerWithIdentifier:@"View2"];
}
- (IBAction) button3 {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SecondController *ViewForButton3 = [mainStoryboard instantiateViewControllerWithIdentifier:@"View2"];
}
@end
<小时/>
我知道如何将图像添加为孔 View 的 subview ,但我需要它位于 ScrollView 中! 我现在如何在此类中实现 ScrollView 并向其添加 subview ?
PS:我有超过 3 个按钮,但在本例中我只使用了 3 个。
最佳答案
为每个 UIButton
提供 Tag
并在点击按钮时获取标签,并将此标签传递给 YourSecondViewController
并为您想要的图像添加条件显示点击按钮的基础。
关于ios - 将 subview 添加到 subview ,但来自另一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14539199/