Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 将情节提要视图添加为子视图时发送到解除分配实例的消息_Ios_Objective C_Xcode_Memory Management_Uiviewcontroller - Fatal编程技术网

Ios 将情节提要视图添加为子视图时发送到解除分配实例的消息

Ios 将情节提要视图添加为子视图时发送到解除分配实例的消息,ios,objective-c,xcode,memory-management,uiviewcontroller,Ios,Objective C,Xcode,Memory Management,Uiviewcontroller,好的,我对这里发生的事情有一个基本的了解,但是我在修复它方面有困难。我希望有人能告诉我我做错了什么 我有一个漂亮的应用程序,它工作得很好,并且是用故事板和自定义UIViewController构建的,用来处理我的所有代码。我做得很好,直到我需要处理推送通知,将我放在特定视图中并加载一些数据。我今天取得了很大的进步,只是陷入了困境。我现在得到一个objc_sendmsg错误,我知道这与我的内存管理有关。我从未以这种方式初始化过视图,所以我想知道这是否是导致它的原因。基本上,我可以加载一个视图,但之

好的,我对这里发生的事情有一个基本的了解,但是我在修复它方面有困难。我希望有人能告诉我我做错了什么

我有一个漂亮的应用程序,它工作得很好,并且是用故事板和自定义UIViewController构建的,用来处理我的所有代码。我做得很好,直到我需要处理推送通知,将我放在特定视图中并加载一些数据。我今天取得了很大的进步,只是陷入了困境。我现在得到一个objc_sendmsg错误,我知道这与我的内存管理有关。我从未以这种方式初始化过视图,所以我想知道这是否是导致它的原因。基本上,我可以加载一个视图,但之后我再也不能按任何按钮或去任何地方了

代码如下:

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_调用DetailViewController.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

我不确定我做错了什么,但无论我点击该页面上的任何按钮或试图关闭该视图时会发生什么,它都会向我尖叫并生气……我已经想尽一切办法来解决这个问题


谢谢大家

问题在于,您正在创建视图控制器,捕获它的视图,但却让控制器超出范围(可能是在将其释放到您身上的地方使用ARC)

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

无论如何,解决此问题的一种方法是执行
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];

问题是,您正在创建视图控制器,获取其视图,但却让控制器超出范围(可能是使用ARC将其释放到您身上)

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

无论如何,解决此问题的一种方法是执行
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];

错误消息是什么?***-[Leads_调用DetailViewController性能选择器:withObject:withObject:]:发送到已解除分配实例0x1D8693F0的消息是否还有其他信息?错误消息是什么?***-[Leads_调用DetailViewController性能选择器:withObject:withObject:]:发送到解除分配实例0x1D8693F0的消息是否还有其他信息要获取?1个问题。每当我尝试presentViewController时,我都会看到一个黑屏,似乎无法调试…有什么提示吗?我将addSubview行更改为:UIViewController*presentingController=[[[[UIApplication sharedApplication]委托]窗口]rootViewController];[presentingController presentViewController:detailVC动画:是完成:无];我对presentViewController的评论是在我注意到你是从你的应用程序代理那里做这件事之前。因此,相反,创建一个新的示例非情节提要项目,查看它在应用程序委托中的作用,并在此基础上对应用程序委托进行建模(定义
UIWindow
属性并设置其
rootViewController
,或者更好地使用“主情节提要”在你的目标设置中设置,你不必在你的应用程序代理中执行任何操作。明白了。谢谢你的帮助。我开始了解视图的显示方式。我的主工具栏是在目标设置中定义的,但我仍然不确定为什么从appdelegate显示视图会导致黑屏…还有其他想法吗可能是什么原因造成的?@ChrisJenkins如果你定义了“主情节提要”,那么你的应用程序代理不需要做任何特殊的事情,因为iOS会自动为你加载初始场景,
didfishlaunchingwithoptions
不需要做任何愚蠢的事情。但是如果你想手动加载,请离开“主情节提要”空白,然后你将不得不做一些我在修改后的答案中概述的事情。为什么不让“主要情节提要”在你的
didFinishLaunchingWithOptions
中,做到这一点,不要乱动窗口、控制器、视图或其他任何东西?对不起,我一定没有说清楚。整个应用程序工作得很好,我只是在收到通知时尝试呈现正确的视图。所有这些都在DidReceiveMemoteNotification下运行,我一直遇到2个问题中的1个。要么我可以让它弹出信息,不能单击任何东西,要么我的视图就是不显示。子视图让我进入视图,我可以对视图进行编程以获取通知,但从那里每次按下按钮都会崩溃。如果我从窗口执行presentViewController,它只会在我身上显示一个黑屏:/还有一个问题。每当我尝试presentViewController时,我都会看到一个黑屏,似乎无法调试…有什么提示吗?我将addSubview行更改为:UIViewController*presentingController=[[[UIApplication sharedApplication]delegate]window]rootViewController];[presentingController presentViewController:detailVC动画:是完成:否];我对
presentViewController
的评论是在我注意到你从你的应用程序代理那里做这件事之前。因此,相反,创建一个新的示例非故事板项目,看看它在应用程序代理中做了什么,并在此基础上为你的应用程序代理建模(定义
UIWindow
属性并设置其
rootViewController
,或者,更好地,在目标设置中使用“主情节提要”设置,而不使用