iphone - 多次旋转后我的应用程序崩溃

标签 iphone objective-c crash autorotate memory-leaks

尝试多次旋转时,我的应用程序崩溃了。我最初以为这只是iPhone模拟器,所以我将应用程序加载到iPod touch上,并且连续旋转较少后便崩溃了。我怀疑这是我的一种旋转方法中的内存泄漏。我可以认为导致崩溃的唯一地方是willRotateToInterfaceOrientation:duration:。我添加/扩展的与旋转相关的仅有的两种方法是shouldAutorotateToInterfaceOrientation:willRotateToInterfaceOrientation:duration,我不认为这是第一种,因为它仅包含两个词:return YES;。这是我的willRotateToInterfaceOrientation:duration:方法,因此您可以对其进行检查并查看可能的内存泄漏在哪里。

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration 
{
 UIFont *theFont;


 if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
 {
  theFont = [yearByYear.font fontWithSize:16.0];
  yearByYear.font = theFont;
  [theview setContentSize:CGSizeMake(460.0f, 635.0f)];
 }
 else
 {
  theFont = [yearByYear.font fontWithSize:10.0];
  yearByYear.font = theFont;
  [theview setContentSize:CGSizeMake(300.0f, 460.0f)];
 }

 [theFont release];
}

yearByYear是一个UITextView,而view是一个UIScrollView

最佳答案

您不应该发布theFont。您不拥有该对象。

您还可以简化操作:

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration  {

   if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
      yearByYear.font = [yearByYear.font fontWithSize:16.0]
      [theview setContentSize:CGSizeMake(460.0f, 635.0f)];
   }
   else
   {
      yearByYear.font = [yearByYear.font fontWithSize:10.0]
      [theview setContentSize:CGSizeMake(300.0f, 460.0f)];
   }
}

完全摆脱theFont

关于iphone - 多次旋转后我的应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2843618/

相关文章:

iphone - 将导入的数据保存到核心数据 - 无法读回

python - 计时器的 Tkinter 代码使应用程序崩溃(python)

iphone - iPhone应用程式当机(Jettisoned)问题

iphone - 如何在 iPhone 上浏览源代码?

iphone - 如何在 UIWebview 表单中创建键盘的“确定”按钮?

objective-c - 如何使用 Kiwi 异步测试委托(delegate)

ios - 在 iOS 上使用共享横幅切换标签时显示 AdMob 和/或 iAd

excel - 导致 excel 2013 崩溃的用户表单

iphone - 使用 Twitter 登录我的 iPhone 应用程序时出错

iphone - 是否可以将当前的 Modal ViewController 设为 UINavigationController?