开发者

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.

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). 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:

- (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.xib has a UITableViewController with it's respective UITableView. This Table View Controller is linked to a CalendarTableController to which I also generated a .xib file for it.

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.

- (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). 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. URLConnectionClient seems to be generating it, but I don't really know why. The loading of the xml had worked earlier before I rearranged the ViewControllers to work as I have described now.

Any ideas?


It's weird. I fixed the problem but I had to dedicate the whole UIViewController to contain the UITableView. What I did was this:

  1. Create an IBOutlet with the custom UITableViewController (CalendarTableViewController) in the custom UIViewController.
  2. In the loaded .xib file I linked the IBOutlet to a created UITableViewController declared as a CalendarTableViewController.

This way I solved the problem of the UITableViewController being deallocated without reason. But now the image views I had placed in the intermediate UIViewController wouldn't appear. I had to set that UIViewController to contain solely the CalendarTableView and place the image views in the initial UIViewController. Weird, isn't it? I don't like much the hierarchy I created... but for now that will do =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.


Have you tried calling loadView before adding the nested controller's view to the parent's view?

Maybe viewDidLoad is not executing before you add the view and some variables were never initialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜