0

I have a ViewController1.h/m and SettingsViewController.h/m. In ViewController1.m I have this:

ViewController1.h
@property (nonatomic, weak) UIView *settingsView;

ViewController1.m

//alloc init _settingsView
SVC = [[SettingsViewController alloc]init];
[self addChildViewController:SVC];
SVC.view.frame = self.view.bounds;
[_settingsView addSubview:SVC.view];
[SVC didMoveToParentViewController:self];

I don't remove ViewController1 from parent view when I add the settings. It's just off to the side and slides in when I'm toggling the settings view with a button. Inside SettingsViewController I have a table and on a row click I want to slide the SettingsViewController back off the screen and perform a selector from ViewController1...that's where my problem is right now. Here's what I try to do:

SettingsViewController.m

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {
        ViewController1 *VC1 = [[ViewController1 alloc]init];
        [VC1.settingsView setFrame:CGRectMake(320, 0, VC1.view.frame.size.width, VC1.view.frame.size.height)];
        //NSLog(@"%f", VC1.settingsView.center.x);
        //tried:
        //[VC1 performSelector:@selector(...)]; I have the method declared in VC1.h
    }
}

Logging the VC1.settingsView.center.x always gives me 0...when it should be 160. Adding a log statement in VC1 methods when running performSelector DOES log but the rest of the method doesn't run, doesn't slide the SettingsViewController off the screen. Am I not understanding parent/child relationship???

denikov
  • 877
  • 2
  • 17
  • 35

1 Answers1

1

Crap, found the answer after hours of trying...thanks to this

if([self.parentViewController isKindOfClass:[SomeViewController class]]) {
    SomeViewController* viewController = (SomeViewController*)self.parentViewController;
    [viewController foo];
}
Community
  • 1
  • 1
denikov
  • 877
  • 2
  • 17
  • 35