我会做的是:
1) 为每个视图创建自定义类。
2) 然后我会将 View Classes 设置为我创建的类。
3) 然后我会编写代码来处理您在这些视图类中需要的任何功能。
@interface PageContent : UIView
- (void) showTest : (NSString *) textToShow;
@end
@implementation PageContent
- (void) showTest : (NSString *) textToShow
{
//Then here you would do whatever you need to do with this text, and display it
}
@end
@interface SoundPlayer : UIView
- (void) playSound;
@end
@implementation SoundPlayer
-(void) playSound
{
//Do whatever you need to do with the sound here.
}
@end
4) 然后在您的视图控制器类中为这些视图中的每一个创建出口。
//So your View Controller Class would look something like this.
@interface YourViewController : UIViewController
@property (strong, nonatomic) IBOutlet Page *page;
@property (strong, nonatomic) IBOutlet PageContent *pageContent;
@property (strong, nonatomic) IBOutlet SoundPlayer *soundPlayer;
@end
5) 然后在您的 View Controller @implementation 中,您可以执行类似的操作
@implementation YourViewController
-(void) showContent
{
[self.pageContent showText:@"Text To Show"];
}
-(void) playSound
{
[self.soundPlayer playSound];
}
@end
现在,当您在视图控制器中调用这些([self showContent] 或 [self playSound])方法时,它会调用特定视图的方法,这样您就没有一个非常长的不可重用视图控制器.
我只是展示了一个视图示例,我希望你能看到我在这里做什么,并为你需要的一切实现它。