Reputation: 18338
Lets say I have the following xibs:
In the IssueSelectorViewController.h file I have the following:
@interface IssueSelectorViewController : UIViewController <AQGridViewDelegate, AQGridViewDataSource, ReaderViewControllerDelegate,UIScrollViewDelegate, IconDownloaderDelegate>
@property (nonatomic, strong) IBOutlet AQGridView * gridView;
@property (nonatomic, strong) IBOutlet IssueCell *gridViewCellContent;
...
@end
Inside IssueSelectorViewController.xib
, I make an outlet connection from gridView -->Actual Grid View. This makes sense to me as I have a grid view in this object and want to connect to it so I have access to it from code.
Inside IssueCell.xib
when clicking File's Owner, I have an outlet gridViewCellContent
which I make a connection to IssueCell object. This works and allows my program to run, but what is this really doing? In IssueSelectorviewController
I need access to IssueCell to figure out the width and height of each of my cells. I saw this being done in an example, but I don't understand it completely.
EDIT:
Here is where I use self.gridViewCellContent
, how does this work? Which IssueCell is it pointing to?
- (CGSize)portraitGridCellSizeForGridView:(AQGridView *)aGridView
{
[[NSBundle mainBundle] loadNibNamed:@"IssueCell" owner:self options:nil];
return self.gridViewCellContent.frame.size;
}
Upvotes: 2
Views: 4203
Reputation: 17143
"File's Owner" in a nib is a proxy or placeholder. When the nib is actually loaded, any connections to this placeholder are made to the real object that actually owns the nib. So when you do [UIViewController initWithNibName:bundle:], the file's owner placeholder is replaced by the actual view controller object.
It's very similar when you load a custom table view cell (I'm assuming you do that within your tableView:cellForRowAtIndexPath: method). You load the nib, specify an owner, and that owner object gets all the connections that the "file's owner" placeholder had in the nib itself.
I hope that makes sense?
If you post your tableView:cellForRowAtIndexPath:, you can see where that connection is made. (Or if you registered a nib for the tableView then you specified the owner when you created that.)
EDIT
ok, so from the code you posted:
[[NSBundle mainBundle] loadNibNamed:@"IssueCell" owner:self options:nil];
You specified the owner as 'self', so 'self.gridViewCellContent' should be the new cell that was just loaded from the nib, presuming you made the right connections in the nib. When the nib is loaded, any connection made to "file's owner" in the nib will now be made to 'self' (your view controller).
(Seems strange you are loading the nib there, when that method expects an AQGridView* as a parameter, but I guess you know what you're doing there)
Upvotes: 9