上ViewDidAppear
,
[self performSelectorInBackground:@selector(generatePdf) withObject:nil];
叫做。这会在加载视图后立即生成一个大 PDF。为了考虑内存不足的问题,我可以在启动后停止该进程吗?使用
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(generatePdf) object:nil];
不起作用,大概是因为视图一出现就已经调用了它。如果应用程序收到,我想停止这个过程,didReceiveMemoryWarning
所以我正在寻找一种解决方案,可以在我的- (void)didReceiveMemoryWarning
方法中完全停止它
- (void)viewDidAppear:(BOOL)animated
{
LogCmd();
[super viewDidAppear:animated];
if (self.pdfData == nil) {
// Generate PDF
[self performSelectorInBackground:@selector(generatePdf) withObject:nil];
}
}
....some code
- (void)didReceiveMemoryWarning {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(generatePdf) object:nil];
}