我有一个UINavigationController,其中有一个带UITableView的MainViewController和一个ToolBar按钮。选择UITableViewCell将推至SecondViewController,而点击“工具栏”按钮将推至ThirdViewController,两者都具有StoryBoard segue。
两个ViewController都首次按下OK,但是当UINavigationController首先按下SecondViewController并弹出回到MainViewController时,再按下ThirdViewController将导致应用程序崩溃。所以我认为ThirdViewController's代码一定有问题,但是错误消息是:

SecondViewController respondsToSelector:]: message sent to deallocated instance 0x115621d0


奇怪的是为什么我按下SecondViewController时错误消息中出现ThirdViewController吗?
我设置了断点,并且prepareForSegue上的MainViewController被无误地调用,viewDidLoad上的ThirdViewController被无误后被调用,但是当我单击viewDidLoad末尾的继续时,应用程序崩溃。
使用启用了“僵尸”的乐器将显示以下内容:


我正在推送ThirdViewController,为什么代码进入SecontViewController segue?我不知道代码有什么问题吗?我正在使用ARC,所以我没有误发布任何内容。

SB的屏幕截图:

所有三个View Controller的类定义

// MainViewController.h
@interface MainViewController : UITableViewController <UIAlertViewDelegate, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, UIPageViewControllerDelegate, UIPageViewControllerDataSource, SecondViewControllerDelegate> {
    BOOL _thumbnailTapped;

}

- (void)showQuickTour:(id)sender;
- (void)Purchased;
- (IBAction) pickThumbnailImage:(id)sender;


@property (strong, nonatomic) UIPageViewController *pageViewController;
@property (strong, nonatomic) NSArray *pageTitles;
@property (strong, nonatomic) NSArray *pageImages;
@property (strong, nonatomic) NSArray *pageImages_3_5;


@property (nonatomic, weak)   IBOutlet UIBarButtonItem *editOptionsLabel;
@property (nonatomic, strong) NSCache* thumbnailCache;
@property (nonatomic, strong) NSCache* emailCountCache;
@property (nonatomic, weak)   NSIndexPath* currentIndexPath;
@property (nonatomic, readwrite) BOOL deleting;
@property (nonatomic, weak)   ABContact *returnedMailingList;
@property (nonatomic, strong) SoundEffect* deleteFX;

@end


//SecondViewController.h
@protocol SecondViewControllerDelegate <NSObject>
- (void)getBackCurrentMailingList:(id)controller didFinishEnteringItem:(ABContact *)currentMailingList;
@end


@protocol ModalViewDelegate
@optional
- (void) getBackGroup:(NSDictionary *) group;
- (void) getBackContacts:(NSArray *)c andEmails:(NSArray *)e;
- (void) getBackPastedContacts:(NSArray *)contacts;
- (void) getBackPullView:(BOOL)pullled;
@end

@interface SecondViewController : UITableViewController <ModalViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, UIAlertViewDelegate, MFMailComposeViewControllerDelegate>
{
    ABContact *currentML;
    BOOL _isViewPulled;
}

- (IBAction) pickImage:(id)sender;
- (IBAction) composeEmail:(id)sender;
- (IBAction) PasteGroup:(id)sender;
- (IBAction) dismissPopUp:(id)sender;

@property (nonatomic, weak)     IBOutlet UIBarButtonItem *composeButton;
@property (nonatomic, strong)   NSCache*                thumbnailCache;
@property (nonatomic, strong)   ABContact*              currentML;
@property (nonatomic, strong)   NSMutableDictionary*    currentMailingList;
@property (nonatomic, strong)   NSArray*                pastedContatcs;
@property (nonatomic, strong)   NSDictionary*           groupDictionary;
@property (nonatomic, readwrite) ABRecordID             currentRecordID;
@property (nonatomic, strong)   UIView*                 fadingView;
@property (nonatomic, strong)   UILabel*                fadingLabel;
@property (nonatomic, strong)   UIActivityIndicatorView* fadingActivityIndicator;
@property (nonatomic, weak)     id <SecondViewControllerDelegate> delegate;
@property (nonatomic, strong)   SoundEffect* deleteFX;

@end


//ThirdViewController.h
@interface SettingsViewController : UIViewController <SKPaymentTransactionObserver, SKProductsRequestDelegate>
{

}

@property (strong, nonatomic) SKProductsRequest *request;
@property (strong, nonatomic) SKProduct *product;
@property (strong, nonatomic) NSString *productID;
@property (weak,   nonatomic) IBOutlet UILabel *versionLabel;
@property (weak,   nonatomic) IBOutlet UILabel *productLabel;
@property (weak,   nonatomic) IBOutlet UITextView *productDescription;
@property (weak,   nonatomic) IBOutlet UIButton *purchaseButton;
@property (weak,   nonatomic) IBOutlet UIButton *buyButton;
@property (weak,   nonatomic) IBOutlet UISwitch *soundFXSwitch;
@property (weak,   nonatomic) IBOutlet UIActivityIndicatorView *loadingIndicator;

- (IBAction)buyProduct:(id)sender;
- (IBAction)restorePurchase:(id)sender;
- (IBAction)switchSoundFX:(id)sender;
- (IBAction)showQuickTour:(id)sender;

-(void)getProductID:(UIViewController *)viewController;

@end

最佳答案

是否检查是否将secondVC分配为UINavigationControllerDelegate?如果是,请尝试在viewWillDisappear中将该值设置为nil

关于ios - UINavigation Controller在显示ViewController时崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24229318/

10-10 10:05