-
Notifications
You must be signed in to change notification settings - Fork 0
MagicV2ViewController
MagicV2ViewController is a subclass of UITableViewController. It's the main class.
-
The MagicV2 handle cache with Datas validity duration. Cache is used for both Detail and List Interactors. If a specific duration (in seconds) is set, the Interactor will be asked to retrieve cached datas instead of requesting new datas. By default, cache isn't enabled. See MagicV2DetailInteractor to enable the cache.
-
When the
viewDidLoad:method is called, it init the Magic components. -
By default the MagicV2ViewController handle the
tableView:numberOfRowsInSection:method by returning the number of objects contained into thelistInteractor.results.
1) [Optional] implement initDetailInteractor methods and set the detailInteractor :
- (void)initDetailInteractor
{
self.detailInteractor = [[MyDetailInteractor alloc] init];
}Setting the detailInteractor will make the MagicV2 to first ask the detailInteractor to retrieve his data. When it's done, the listInteractor will be asked to retrieve datas too.
Implement the MagicV2DetailInteractorDelegate method magicDetailInteractorDidReceivedResults: forLoadingType: to get informed when the retrieve ended.
2) [Required] implement initListInteractor methods and set the listInteractor :
- (void)initListInteractor
{
self.listInteractor = [[MyListInteractor alloc] init];
}
Setting the listInteractor is mandatory. It will be used to poppulate the UItableView. The listInteractor handle paging.
Implement the MagicV2ListInteractorDelegate method magicListInteractorDidReceivedResults: forLoadingType: to get informed when the retrieve ended.
3) [Optional] implement magicTableHeaderView methods and return the UITableView tableHeaderView :
- (UIView<MagicV2TableHeaderViewDelegate>*)magicTableHeaderView
{
return mYHeaderView;
}
This view will be added to the tableHeaderView. The returned view will receive a callback updateMagicHeaderViewForMagicController: when the detailInteractor finish retrieving datas.
4) [Required] implement tableViewCellForTableView:forIndexPath: methods and return cells according to the listInteractor.results objects :
- (UITableViewCell*)tableViewCellForTableView:(UITableView*)tableView forIndexPath:(NSIndexPath*)indexPath
{
if ([self.listInteractor.results count] > indexPath.row)
{
id lObject = [self.listInteractor.results objectAtIndex:indexPath.row];
if ([lObject isKindOfClass:[MyObject class]])
{
return [TableViewCellGenerator tableViewCellForTableView:tableView object:MyObject];
}
}
UITableViewCell* lCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"bugCell"];
lCell.textLabel.text = @"test cell";
return lCell;
}
5) [Required] implement tableViewCellHeightForTableView:forIndexPath: methods and return cells height according to the listInteractor.results objects :
- (UITableViewCell*)tableViewCellHeightForTableView:(UITableView*)tableView forIndexPath:(NSIndexPath*)indexPath
{
if ([self.listInteractor.results count] > indexPath.row)
{
id lObject = [self.listInteractor.results objectAtIndex:indexPath.row];
if ([lObject isKindOfClass:[MyObject class]])
{
return kMyObjectCellHeight;
}
}
return 0.0f;
}
6) [Optional] implement magicListInteractorDidReceivedResults:forLoadingType: methods to update your view when the list data retrieving finish :
- (void)magicListInteractorDidReceivedResults:(MagicV2ListInteractor*)listInteractor forLoadingType:(MagicV2TableViewLoadingType)loadingType
{
[self.tableView reloadData];
[self.refreshControl endRefreshing];
}
/!\ Don't forget to hide the UIRefreshControl.
7) [Optional] override defaultLoadingCellForTableView: methods and return your own UITableViewCell to customize the default loading cell displayed when the list is empty and interactors are retrieving datas.
8) [Optional] override noResultCellForTableView: methods and return your own UITableViewCell to customize the no results available message displayed when the list is empty after the Interactors finish requesting.
9) [Optional] override pagingCellForTableView: methods and return your own UITableViewCell to customize the UITableView last cell displayed while paging hasn't ended.