【问题标题】:receiving memory warning in simple uipageviewcontroller app在简单的 uipageviewcontroller 应用程序中接收内存警告
【发布时间】:2016-01-27 15:23:47
【问题描述】:

我有一个基于默认页面应用程序的 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];
}

当我收到内存警告时,我的应用程序没有响应,并且我无法再在视图之间滑动。我做错了什么?

【问题讨论】:

  • 点击debug / pause看看主线程做了什么

标签: ios objective-c xcode uipageviewcontroller didreceivememorywarning


【解决方案1】:

您的应用程序可能会收到内存警告,因为您在启动时实例化了所有 ViewController。

您不应该将 viewController 存储在 NSArray 中,而应仅在需要时实例化它们。

看看这个答案:Releasing unused pages in UIPageViewController

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 2012-04-08
    • 2013-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多