我相信一个 UIViewController 子类可以提供你需要的一切。您只需要提供支持每种不同类型图片所需的差异。让我们假设这些差异只是它显示的图片的描述和类型:
MyViewController.h:
@MyViewController : UIViewController
@property (strong, nonatomic) NSString *description;
@property (strong, nomatomic) NSString *type;
// Designated initializer
- (id)initWithNibName:(NSString *)nibName
bundle:(NSBundle *)nibBundle
description:(NSString *)description
type:(NSString *)type;
@end
MyViewController.m:
@implementation MyViewController
- (id)initWithNibName:(NSString *)nibName
bundle:(NSBundle *)nibBundle
description:(NSString *)description
type:(NSString *)type
{
self = [super initWithNibName:nibName bundle:nibBundle];
if (self != nil)
{
self.description = description;
self.type = type;
}
return self;
}
- (NSArray *)fetchPics
{
NSMutableArray *pics = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.somewhere.com/fetchPics?type=%@", self.type]];
...
return pics;
}
@end
然后它应该只是在必要时创建视图控制器的情况:
MyViewController *catVC = [[MyViewController alloc] initWithNibNamed:@"Something" bundle:nil description:@"Cats" type:@"cat"];
...