SWRevealViewController from one controller to another
-
21-12-2019 - |
Question
I'm working with SWRevealViewController
to have a side menu on an application. It works as expected from the side menu to a controller. What I'd like to do now is use SWRevealViewController
again from one controller to another (both UITableViewController
).
From Side Menu to Controller 1 to Controller 2:
This is what I've tried to do so far:
Set up the Real View Controller Segue
from the Interface Builder to the second Controller with identifier "articlesSegue"
.
And in the first Controller I use didSelectRowAtIndexPath
and prepareForSegue
to show the second Controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set selected issue to var
_selectedIssue = _feedItems[indexPath.row];
// Manually call segue to detail view controller
[self performSegueWithIdentifier:@"articlesSegue" sender:self];
}
#pragma mark Segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get reference to the destination view controller
TableViewController *tableVC = segue.destinationViewController;
// data used in the second Controller
tableVC.self.type = @"category";
tableVC.self.data = [_selectedIssue.ID stringValue];
}
Selecting an item from the list is displayed as selected but nothing happens.
I've tested it out using a Push Segue and it worked, still I prefer it to working with SWRevealViewController
.
I did find this question but I'm not too sure how it has to be implemented, SWRevealViewController - manually switch to another view?.
Solution
As @Anbu.Kathik explained I could not use the SWReveal
to move from Controller
to another Controller
. I've solved it by using the same TableViewController
, I've added a property type
to check which is the current 'tableview' and simply updating the table when an item is selected on didSelectRowAtIndexPath
.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// check type of current tableview - if category display article
if ([self.type isEqualToString:@"category"]) {
// display single article
_selectedArticle = _feedItems[indexPath.row];
[self performSegueWithIdentifier:@"detailSegue" sender:self];
}
else {
// else if issue display list of articles on the same TableViewController
_selectedIssue = _feedItems[indexPath.row];
self.type = @"category";
self.data = [_selectedIssue.ID stringValue];
[_homeModel downloadItems:self.type :self.data];
}
}
Using [self.tableView reloadData]
reloads the table with new data.