I have this code here to check on the existence of the ViewController
. And unfortunately it doesn't work. The thing is, it is executed at the moment of another VC popping from the Navigation Stack
:
- (void) leftViewDidHide{
if ([((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers objectAtIndex:1]) {
SGServerListViewController *sample = [[[((AppDelegate *)[UIApplication sharedApplication].delegate).frontViewController.navigationController.viewControllers objectAtIndex:1]childViewControllers] objectAtIndex:0];
[sample.serverTableView setUserInteractionEnabled:YES];
}
}
The app crashes with an exception breakpoint pointing me to the line with an if
statement. Any ideas on what could be wrong here? I'm just trying to check if this VC
is there and if it is - execute the code.
NSArray *viewControlles = [self.navigationController.viewControllers];
for (int i = 0 ; i <viewControlles.count; i++){
if ([YourVC isKindOfClass:[viewControlles objectAtIndex:i]]) {
//Execute your code
}
}
NSArray *controllerArray = [self.navigationController.viewControllers];
//will get all the controllers added to UINavigationController.
for (id controller in controllerArray)
{
// iterate through the array and check for your controller
if ([controller isKindOfClass:[checkYourController class]])
{
//do your stuff here
}
}
just for an idea containsObject:
method of NSArray
class might also work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With