#Components
JSBaseViewController
JSBaseTableViewController
JSBaseCoreDataTableViewController
JSBaseTableViewCell
#Highlights
- Adjusting your view automatically along with the keyboard.
- Stick a view (like a textfield) on top of the keyboard.
- Progress HUD showing / hiding in all your View Controllers.
- Automatic cell nibs instantiation. Just code what is important.
- Pull to refresh in one line of code.
- Very easily implement tables that show data from Core Data.
#Features
Forget about implementing the right - initWith, awakeFromNib... just implement
- (void)setUp;
and be sure it will be called once in all cases.
Very handy for when you make long-running requests from any view controller.
- (void)showWaitView;
- (void)showWaitViewAndDimScreen;
- (void)showWaitViewWithMessage:(NSString*)message;
- (void)hideWaitView;
- (void)hideWaitViewWithSuccessMessage:(NSString *)message;
- (void)hideWaitViewWithErrorMessage:(NSString *)message;
Forget about dealing with nib loading, cell reusing, etc. Just set the name of the nib file that corresponds to the cell that the table will use in the setUp method like this:
- (void)setUp
{
self.cellNibName = @"MyCellNibFileName";
}
and than you can just implement this method to make the necessary adjustments to the cell (which you can cast to your own UITableViewCell subclass):
- (UITableViewCell *)tableView:(UITableView *)tv configureCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
Only requirement is that your cell inherits from JSBaseTableViewCell.
Just set
self.tableHasPullToRefresh = YES;
in your setUp method. And then use these two methods:
/* Implement this method to respond to drag to refresh events */
- (void)reloadTableViewDataSource;
/* Call this method when the drag to refresh load has finished */
- (void)doneLoadingTableViewData;
Just set:
self.tableHasInfiniteScrolling = YES;
And you will be called to this method:
- (void)loadMoreItemsAfterTheLastOne;
Just by calling
[self registerForKeyboardNotifications];
in your setUp method. If it's a regular view controller, you can implement
- (void)viewWillAdjustForKeyboardHidden:(BOOL)keyboardHidden keyboardHeight:(CGFloat)keyboardHeight;
which will be called inside an animation block that goes along with the keyboard. If it's a Table View Controller, the table will automatically adjust. if you want to provide custom behaviour, you can implement
- (void)tableViewWillBeResizedToAdjustForKeyboardHidden:(BOOL)keyboardHidden keyboardHeight:(CGFloat)keyboardHeight;
which will be called inside the animation block.
(very convenient for typical chat / comment views). Just implement the method:
- (UIView *)keyboardAuxView;
and return the view that you want to stay on top of the keyboard.
(and that are automatically refreshed with changes in them). Inherit from JSBaseCoreDataTableViewController and implement:
- (NSFetchRequest *)fetchRequest;
to return an NSFetchRequest object corresponding to the query you want to perform. And then implement this other method that will be called on you:
- (UITableViewCell *)tableView:(UITableView *)tv configureCell:(UITableViewCell *)cell forManagedObject:(NSManagedObject *)object;
- Have all your cells automatically be correctly reused even if you forget to set the reuse identifier in Interface Builder:
For this you only need to make your cell classes inherit from JSBaseTableViewCell.
#Submodules
- JSProgressHUD: https://github.com/JaviSoto/JSProgressHUD
- EGOTableViewPullRefresh: https://github.com/enormego/EGOTableViewPullRefresh
#Installation
First clone the repository:
$ git clone [email protected]:JaviSoto/Base-iOS-View-Controllers.git
$ cd Base-iOS-View-Controllers
$ git submodule init
$ git submodule update
Second. Drag the BaseControllers folder to your Xcode project. And remove the unneeded files (like the EGOTableViewPullRefresh sample project)
Third. Link against these frameworks:
CoreData
QuartzCore
Fourth. (Optional) Modify the method - (NSManagedObjectContext *)managedObjectContext in JSBaseViewController by adding the needed logic to create a NSManagedObjectContext passing your NSPersistantStoreCordinator (ONLY IF YOU WANT TO USE CORE DATA).
#Credits
Thanks to Oriol Blanc, because a lot of this is thanks to him :)