Reputation: 1974
I'm creating an app and starting to run into a problem that the size of my app is getting pretty big and I'm looking for ways I can decrease the size. I have over 50 xibs so I think that's one of the areas I can improve on. I have a lot of xibs that are all matched up to a different View Controller eacbh and some of them are very similar.
I'd like to be able to take these similar ViewControllers, and reuse one xib for all of them to cut down on size.
I'm thinking inheritance would be the best way to do this. Create a "SuperViewController" that all my other ViewControllers extend. The SuperViewController will be hooked up to the xib and then I could reuse what I need.
Here's what I have in the SuperViewController.m:
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *emptyView;
@property (weak, nonatomic) IBOutlet UIButton *currentButton;
@property (weak, nonatomic) IBOutlet UIButton *quitWalkButton;
All of those IBOutlets are in my xib files and are in all of my ViewControllers. Each ViewController just does slightly different things with those.
Problem is, because these are in my .m file they are essentially private and I can't access them from the subclasses. I could put them in the .h file and be able to access them, but I don't want them public I want them "protected". Also, I'm not sure how actions like click will work because those are always in the .m file.
I'm beginning to think that Inheritance isn't the way to go to reuse xib files in multiple View Controllers, but I'm not sure what's the accepted way to do this. Any advice either way is appreciated.
Upvotes: 1
Views: 1592
Reputation: 4728
I'd leave those outlets right where they are at the top of the .m file of the superclass, and put a second accessor for each in a separate header/ extension.
//myViewControllerSuperclass+privateOutlets
# import "myViewControllerSuperclass"
@interface myViewControllerSuperclass(privateOutlets)
//this header to be imported to your subclasses
@property (readonly) UITableView *tableView_;
@property (readonly) UIView *emptyView_;
@property (readonly) UIButton *currentButton_;
@property (readonly) UIButton *quitWalkButton_;
//note trailing underscore..
//myViewControllerSuperclass.m
# import "myViewControllerSuperclass+privateOutlets"
@implementation myViewControllerSuperclass
#pragma mark - privateOutlets
-(UITableView *)tableView_{
return self.tableView;
}
-(UIView *)emptyView_{
return self.emptyView;
}
-(UIButton *)currentButton_{
return self.currentButton;
}
-(UIButton *)quitWalkButton_{
return self.quitWalkButton;
}
//these 'getters' just point to the existing outlets..
Upvotes: 1
Reputation: 3939
In apps I've seen, the large consumer of space is the media, not the XIB data. Large images, video, audio, etc. eat up space pretty quick.
If something is actually consuming space inside the XIB's it might be easier to find it by viewing the XML inside the file rather than looking at Xcode' visual editor. You may find large blocks of binary data.
Upvotes: 1