ios - 将 subview 添加到 subview ,但来自另一个类

标签 ios cocoa-touch cocoa class subclass

我有一个名为 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/

相关文章:

iOS,如何处理 iCloudKit 事务的发布通知请求?

cocoa - 事件的发生日期与开始日期有何不同?

objective-c - 我怎样才能摆脱这种冲突类型的警告?

ios - UITableViewCell 文本在 DispatchQueue 上缩小

ios - 在 UIScrollView 中从屏幕右侧计算 contentOffset

iphone - 应用程序中的多个用户配置文件/帐户 - 持久性

objective-c - 显示带有许多可点击 URL 的文本

ios - App Store 禁止 performSelector 和 respondsToSelector 吗?

iphone - 将 Controller 插入堆栈后,后退按钮未显示

objective-c - 在同一个分隔符上多次拆分 NSString