0

Okay, I have a basic understanding of what is happening here, but am having trouble fixing it. I am hoping someone can walk me through what I'm doing wrong here...

I have a nifty app that works great and was built with the storyboard and custom UIViewControllers to handle all my code. I was doing really well, until I needed to handle my push notifications by dropping me in a specific view and loading some data. I made a lot of headway today and just got stuck in a bad way. I am now getting an objc_sendmsg error and I know it has to do with my memory management. I've never initialized a view in this way, so I'm wondering if that's what's causing it. Basically, I can load a view, but I can never push any buttons or get anywhere after that.

Here's the code:

AppDelegate.m

    UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *detailVC = [storyBoard instantiateViewControllerWithIdentifier:@"Leads_Calls_SB"];
    [self.window addSubview:detailVC.view];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"callReceived"
                                                            object:nil
                                                          userInfo:userInfo];

    [self.window makeKeyAndVisible];

Leads_CallsDetailViewController.h

@property (strong, nonatomic) IBOutlet UILabel *cName;
@property (strong, nonatomic) IBOutlet UILabel *cStart;
@property (strong, nonatomic) IBOutlet UILabel *cNumber;
@property (strong, nonatomic) IBOutlet UILabel *cStart2;
@property (strong, nonatomic) IBOutlet UILabel *cEnd;
@property (strong, nonatomic) IBOutlet UILabel *cDuration;
@property (strong, nonatomic) IBOutlet UILabel *cStatus;
@property (strong, nonatomic) IBOutlet UILabel *cProvider;
@property (strong, nonatomic) IBOutlet UILabel *cLineType;
@property (strong, nonatomic) IBOutlet UILabel *cCity;
@property (strong, nonatomic) IBOutlet UIView *innerView;
@property (strong, nonatomic, retain) IBOutlet UIButton *backStyle;


@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;

@property (strong, nonatomic, retain) NSString *cNotifID;

@property (strong, nonatomic, retain) NSString *cNameText;
@property (strong, nonatomic, retain) NSString *cNumberText;
@property (strong, nonatomic, retain) NSString *cStartText;
@property (strong, nonatomic, retain) NSString *cEndText;
@property (strong, nonatomic, retain) NSString *cCallStatusText;
@property (strong, nonatomic, retain) NSString *cLatitudeText;
@property (strong, nonatomic, retain) NSString *cLongitudeText;
@property (strong, nonatomic, retain) NSString *cCityText;
@property (strong, nonatomic, retain) NSString *cLineTypeText;
@property (strong, nonatomic, retain) NSString *cProviderNameText;
- (IBAction)back:(id)sender;
@property (strong, nonatomic) IBOutlet MKMapView *map;

- (IBAction)forward_lead:(id)sender;
- (IBAction)call_lead:(id)sender;
- (IBAction)add_lead:(id)sender;

@property (strong, nonatomic) IBOutlet UIButton *bottomMessage;
@property (strong, nonatomic) IBOutlet UIButton *bottomCalls;
@property (strong, nonatomic) IBOutlet UIButton *bottomReports;
@property (strong, nonatomic) IBOutlet UIButton *bottomHome;

.m

- (IBAction)back:(id)sender {
    if (self.cNotifID != nil)
    {
        [self.view removeFromSuperview];
    }
    else {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

I'm not sure what I'm doing wrong, but no matter what happens if I hit any button on that page or try to dismiss the view, it screams at me and gets angry...I've tried everything I can think of to figure this out.

Thanks guys!

4

1 回答 1

3

问题是你正在创建你的视图控制器,抓住它的视图,但是让控制器超出了范围(并且可能使用了它在你身上释放的 ARC)。

在我最初的回答中,我认为目标只是考虑呈现标准初始视图控制器的不同方式。但事实并非如此。问题是当某些事件发生时如何呈现一个新场景(在我的示例中,我正在这样做openURL,但您大概可以这样做以响应通知等)。

无论如何,解决这个问题的一种方法是执行presentViewController. 因此,您可以执行以下操作:

// determine the current controller (in case you've already done some modal segues)

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIViewController *currentController = window.rootViewController;
while (currentController.presentedViewController)
    currentController = currentController.presentedViewController;

// load the controller for the new scene

UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *newController = [storyBoard instantiateViewControllerWithIdentifier:@"Leads_Calls_SB"];

// perform a modal transition to the new scene

[currentController presentViewController:newController animated:NO completion:nil];
于 2013-07-08T19:48:35.077 回答