简体   繁体   English

UITableViewController在UIViewController内的UIViewController内加载问题

[英]UITableViewController loading inside a UIViewController inside a UIViewController issue

I don't really know if what I'm doing is the right way to do it. 我真的不知道我在做什么是否是正确的方法。 Right now it seems to be working until it hits a certain point with a EXC_BAD_ACCESS message. 现在,它似乎一直在起作用,直到通过EXC_BAD_ACCESS消息达到特定点为止。

I'll describe what I'm doing as best and with the most relevant details I can tell: I have a CalendarViewController that inherits UIViewController which is loading from a .xib file (CalendarViewController.xib). 我将描述我正在做的最好的事情,并能告诉我最相关的细节:我有一个CalendarViewController,它继承了UIViewController,后者是从.xib文件(CalendarViewController.xib)加载的。 The class contains a UIView called contentView which I created and which I initialize with another nib file based on a class which is also inherited from UIViewController: 该类包含一个名为contentView的UIView,它是我创建的,并基于另一个也从UIViewController继承的类的nib文件进行初始化:

- (void)viewDidLoad {

      [super viewDidLoad];

      calendarView = [[CalendarView alloc] initWithNibName:@"CalendarView" bundle:nil];

      [contentView addSubview:calendarView.view]; 

   }

(calendarView is the class inheriting UIViewController and viewDidLoad is from CalendarViewController. (calendarView是继承UIViewController的类,而viewDidLoad是从CalendarViewController继承的类。

CalendarView.xib has a UITableViewController with it's respective UITableView. CalendarView.xib具有一个UITableViewController及其各自的UITableView。 This Table View Controller is linked to a CalendarTableController to which I also generated a .xib file for it. 该表视图控制器链接到CalendarTableController,我也为其生成了一个.xib文件。

Everything is being created just right (apparently) but it is crashing somewhere very unexpected. 一切都在正确地创建(显然),但是它崩溃的地方非常出乎意料。 CalendarTableController also implements a DateLoaderDelegate which loads information from an xml on an external url. CalendarTableController还实现了DateLoaderDelegate,它从外部URL上的xml加载信息。

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

   // When the data has all finished loading, we set a copy of the  
  // loaded data for us to access. This will allow us to not worry about
 //  whether a load is already in progress when accessing the data. 

    self.lastLoadedMatchXMLData = [self.matchXMLData copy]; 

 // Make sure the _delegate object actually has the xmlDidFinishLoading     
 // method, and if it does, call it to notify the delegate that the     
 // data has finished loading.  

 if ([_delegate respondsToSelector:@selector(xmlDidFinishLoading)])
 {      
     [_delegate xmlDidFinishLoading];
 } 

} }

The application is getting to this point without any problem. 应用程序到此为止没有任何问题。 _delegate is containing the correct object (a CalendarTableController which implements the DateLoaderDelegate). _delegate包含正确的对象(实现DateLoaderDelegate的CalendarTableController)。 But when it arrives to the line: 但是当到达终点时:

  if ([_delegate respondsToSelector:@selector(xmlDidFinishLoading)])

it crashes with the EXC_BAD_ACCESS, I don't really know the reason, if I look at the debugger, the crash is not occurring in any of my classes as any of them are appearing in the execution stack. 它与EXC_BAD_ACCESS一起崩溃,我真的不知道原因,如果我看一下调试器,那么我的任何类都不会发生崩溃,因为它们中的任何一个都出现在执行堆栈中。 URLConnectionClient seems to be generating it, but I don't really know why. URLConnectionClient似乎正在生成它,但是我真的不知道为什么。 The loading of the xml had worked earlier before I rearranged the ViewControllers to work as I have described now. 在重新排列ViewControllers使其能够正常工作之前,xml的加载已在前面进行了描述。

Any ideas? 有任何想法吗?

It's weird. 有点奇怪。 I fixed the problem but I had to dedicate the whole UIViewController to contain the UITableView. 我已解决问题,但我不得不专用于整个UIViewController来包含UITableView。 What I did was this: 我所做的是:

  1. Create an IBOutlet with the custom UITableViewController (CalendarTableViewController) in the custom UIViewController. 使用自定义UIViewController中的自定义UITableViewController(CalendarTableViewController)创建IBOutlet。
  2. In the loaded .xib file I linked the IBOutlet to a created UITableViewController declared as a CalendarTableViewController. 在加载的.xib文件中,我将IBOutlet链接到创建的UITableViewController,该UITableViewController声明为CalendarTableViewController。

This way I solved the problem of the UITableViewController being deallocated without reason. 这样,我解决了UITableViewController被无故释放的问题。 But now the image views I had placed in the intermediate UIViewController wouldn't appear. 但是现在我放置在中间UIViewController中的图像视图不会出现。 I had to set that UIViewController to contain solely the CalendarTableView and place the image views in the initial UIViewController. 我必须将UIViewController设置为仅包含CalendarTableView并将图像视图放置在初始UIViewController中。 Weird, isn't it? 很奇怪,不是吗? I don't like much the hierarchy I created... but for now that will do =S 我不太喜欢我创建的层次结构...但是现在可以做到= S

Check that you have defined properties for all of your subviews and that you are retaining everything that you need to be. 检查是否已为所有子视图定义了属性,并保留了所有需要的属性。 Bad Access May mean that you're attempting to call respondsToSelector on an object that has been released. 错误的访问权限可能意味着您试图在已释放的对象上调用respondsToSelector

Have you tried calling loadView before adding the nested controller's view to the parent's view? 在将嵌套控制器的视图添加到父视图之前,您是否曾尝试调用loadView

Maybe viewDidLoad is not executing before you add the view and some variables were never initialized. 在添加视图之前,也许viewDidLoad没有执行,并且某些变量从未初始化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM