[英]receiving memory warning in simple uipageviewcontroller app
我有一个基于默认页面的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];
}
收到内存警告时,我的应用程序无响应,无法再在视图之间滑动。 我究竟做错了什么?
您的应用程序可能会收到内存警告,因为您在启动时实例化了所有ViewController。
您不应将viewControllers存储在NSArray中,而应仅在需要时实例化它们。
看看这个答案: 释放UIPageViewController中未使用的页面
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.