我有一个基于默认页面应用程序的uipageviewcontroller应用程序,可作为xcode 7.1的起点
我的数据控制器如下所示:
@interface DataViewController ()
@property (weak, nonatomic) IBOutlet UITextView *descTextView;
@property (weak, nonatomic) IBOutlet UIView *backgroundView;
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIBarButtonItem *startAgainButton;
- (IBAction)settingsButtonPressed:(id)sender;
- (IBAction)startAgainButtonPressed:(id)sender;
@end
@implementation DataViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.dataLabel.text = [self.dataObject title];
self.backgroundImage.image = [UIImage imageNamed:[self.dataObject imageName]];
self.descTextView.text = [self.dataObject desc];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
我的模型控制器如下所示:
@interface ModelController ()
@property (readonly, strong, nonatomic) NSArray *pageData;
@end
@implementation ModelController
- (instancetype)init {
self = [super init];
if (self) {
_pageData = [self loadPageData];
}
return self;
}
- (NSArray *)loadPageData{
//255 173 80
NewsPoint *newspoint1 = [[NewsPoint alloc] init];
newspoint1.title = @"my title";
newspoint1.tintCode = @" ";
newspoint1.imageName = @"news";
newspoint1.desc = @"my desc"
return [[NSArray alloc] initWithObjects:newspoint1, newspoint2, newspoint3, newspoint4, newspoint5, newspoint6, newspoint7, nil];
}
当我收到内存警告时,我的应用程序无法响应,我无法再在视图之间滑动。我做错了什么?
答案 0 :(得分:0)
您的应用程序可能会收到内存警告,因为您在启动时实例化所有ViewControllers。
您不应将viewControllers存储在NSArray中,而是仅在需要时将其实例化。