receiving memory warning in simple uipageviewcontroller app

237 views Asked by At

I have a uipageviewcontroller app based on the default page based app available as a starting point in xcode 7.1

My data controller looks like the following:

@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];

}

My model controller has looks like the following:

@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];
}

When I receive my memory warning my app goes unresponsive and I can no longer swipe between views. What am I doing wrong?

1

There are 1 answers

0
vmeyer On

Your application may receive Memory Warning because you instantiate all ViewControllers at launch.

You should not store viewControllers in an NSArray but instantiate them only when you need it.

Take a look at this answer : Releasing unused pages in UIPageViewController