0

我有一个 ViewController1.h/m 和 SettingsViewController.h/m。在 ViewController1.m 我有这个:

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];

添加设置时,我不会从父视图中删除 ViewController1。当我用按钮切换设置视图时,它就在一边并滑入。在 SettingsViewController 内,我有一个表格,然后单击一行,我想将 SettingsViewController 滑出屏幕并从 ViewController1 执行选择器……这就是我现在的问题所在。这是我尝试做的事情:

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
    }
}

记录VC1.settingsView.center.x总是给我 0 ......当它应该是 160 时。在运行performSelectorDOES 日志时在 VC1 方法中添加一个日志语句,但该方法的其余部分没有运行,不会将 SettingsViewController 滑出屏幕。我不了解父母/孩子的关系吗???

4

1 回答 1

1

废话,经过数小时的尝试找到了答案……多亏了这个

if([self.parentViewController isKindOfClass:[SomeViewController class]]) {
    SomeViewController* viewController = (SomeViewController*)self.parentViewController;
    [viewController foo];
}
于 2014-08-08T14:04:04.933 回答