首页 > 其他 > 详细

[HelpViewController respondsToSelector] message sent to deallocated instance

时间:2015-03-25 23:10:59      阅读:180      评论:0      收藏:0      [点我收藏+]

Yesterday I have met one annoying problem: after I have set up IAP (Inner App Purchase ), 

I try to do the test, when I purchase the first time, it is no problem at all, but if I back to the main window from the subview, and then enter subview to purchase again, the App crashed. 

      The following is the screen shot: 

技术分享

 

     I have tried many times to locate the problem, and I have found it always after I have back to superview and enter subview, the problem always stop at: [[SKPaymentQueue defaultQueue] addPayment:payment];

     Then I searched it in google, and have found the same problem in stackoverflow.com

http://stackoverflow.com/questions/11170614/viewcontroller-respondstoselector-message-sent-to-deallocated-instance-crash

this article said the crash reason is "The crash occurs when that controller was dealloc‘ed but was still the delegate for the view controller.”

according to this article, i have added some codes below: 

-(void) viewWillDisappear:(BOOL) animated

{

    [super viewWillDisappear:animated];

    if ([self isMovingFromParentViewController])

    {

        if (productsRequest.delegate == self)

        {

            productsRequest.delegate = nil;

        }

    }

}

    but the problem still there!

 

     Then I thought it should related with dealloc  , because  "message sent to deallocated instance”. so I search method  -(void)dealloc , the method is already there , came from init view controller, there is some description of  “we need to manually stop observing any NSNotificationCenter notifications. Otherwise we could get "zombie" crashes”. And then I have found I add one observer in “view did load", but I have not removed it after view controller deallocated. 

 

-(void)viewDidLoad 

    { 

  [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; object:nil];

    }

 

     After I have removed Transaction Observer in dealloc , then the problem solved.

 

 -(void)dealloc

 {

        [[SKPaymentQueue defaultQueue] removeTransactionObserver:self];

 }

[HelpViewController respondsToSelector] message sent to deallocated instance

原文:http://www.cnblogs.com/myblog-12368/p/4367034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!