Closed ozamihir1990 closed 6 years ago
Your mapviewController is not presented with SWRevealViewController, so it does not know it.
Use:
self.revealViewController().pushFrontViewController(mapviewController, animated: true)
Or setMainViewController:animated
It is not working see my updated code.
SWRevealViewController *revealViewController;
UIViewController *view = [[[UIApplication sharedApplication] keyWindow] rootViewController];
MapVC* mapviewController = [view.storyboard instantiateViewControllerWithIdentifier:@"MapView"];
[revealViewController pushFrontViewController:mapviewController animated:YES];
I am callig from tableviewcell class.
When you write:
SWRevealViewController *revealViewController; it is nil
You have to retrieve the instance of SWRevealViewController in your table view controller or pass it as a reference to the table view cell class.
Could you please give me an example.
In your table view controller:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell" forIndexPath:indexPath];
// Configure the cell...
cell.rvc = self.revealViewController;
cell.title.text = @"Your title";
return cell;
}
In your custom cell:
@interface CustomTableViewCell : UITableViewCell
@property (nonatomic,strong) SWRevealViewController *rvc;
@property (nonatomic,strong) IBOutlet UILabel *title;
@property (nonatomic,strong) IBOutlet UIButton *button;
@end
@implementation CustomTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
[self.button addTarget:self action:@selector(buttonTaped:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)buttonTaped:(void *)sender {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"MapView"];
[self.rvc pushFrontViewController:vc animated:YES];
}
It works. Thank you so much to spend your valuable time for me and gave me the solution.
small doubt, if I have one detail view of View1 and if I want to jump from the detail of View1 to View2 at that scenario what should I do?
You can replace the front view controller like that:
[self.revealViewController setFrontViewController:vc animated:YES];
It is not working because it's View1's detail screen. did I miss something?
How do you present your detail view from view 1?
I am calling from uitableviewcell
class.
UIViewController *view = [[[UIApplication sharedApplication] keyWindow] rootViewController];
DetailVC* detail = [view.storyboard instantiateViewControllerWithIdentifier:@"DetailView"];
//passing data from View1 to DetailVC.
detail.revealViewController = _rvc;
// for iPad issue :
detail.modalPresentationStyle = UIModalPresentationFullScreen;
[view presentViewController:detail animated:true completion:nil];
The controller who present the detailVC must be the front view one not the reveal view controller itself:
SWRevealViewController *view = (SWRevealViewController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
DetailVC *detail = [view.storyboard instantiateViewControllerWithIdentifier:@"DetailView"];
//passing data from View1 to DetailVC.
//detail.revealViewController = _rvc;
// for iPad issue :
detail.modalPresentationStyle = UIModalPresentationFullScreen;
[view.frontViewController presentViewController:detail animated:YES completion:nil];
}
It is not working
In Uitableviewcell
class :
SWRevealViewController *view = (SWRevealViewController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
DetailViewController *detail = [view.storyboard instantiateViewControllerWithIdentifier:@"iPhoneDetailView"];
//passing data from View1 to DetailVC.
detail.modalPresentationStyle = UIModalPresentationFullScreen;
[view.frontViewController presentViewController:detail animated:YES completion:nil];
In details screen button pressed :
MapViewController* mapviewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MapView"];
//passing data from DetailVC to View2.
[self.revealViewController setFrontViewController:mapviewController animated:YES];
I have added breakpoint in setFrontViewController
but it didn't call. I think it is because my self.revealViewController
is nil. Any suggestions?
In your UITableViewCell subclass:
- (void)buttonTaped:(void *)sender {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
DetailVC *detail = [sb instantiateViewControllerWithIdentifier:@"Detail"];
detail.modalPresentationStyle = UIModalPresentationFullScreen;
[_rvc presentViewController:detail animated:YES completion:nil];
}
In your DetailVC:
- (IBAction)goToView2ButtonTaped:(UIButton *)sender {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"View2"];
[self dismissViewControllerAnimated:NO completion:nil];
SWRevealViewController *rvc = (SWRevealViewController *)self.presentingViewController;
[rvc setFrontViewController:vc animated:NO];
[rvc setFrontViewPosition:FrontViewPositionLeft animated:NO];
}
Thank you It's working. I think you are master of SWRevealViewController
I wrote mine too:
https://github.com/iDevelopper/PBRevealViewController
inspired from this one but with more functionalities.
Is it Include those functionalities which I stuck?
Hello, I am having an issue with SWRevealViewController getting nil, Please see my below explanation.
Explanation: I have 2 menus for my 2 screens View1, View2. View1 is a table view in which I have used custom cell, I have added one button in custom cell. So, when I click on that button It jumps to the View2, But the slider navigation doesn't work. Because
SWRevealViewController *revealViewController = self.revealViewController;
getting nil in View2Here is my code which I have written in my
UITableViewCell
classCode which I have written in my View2
It would be great if you can help me to resolve this issue.
Thanks in advance. Mihir Oza