【问题标题】:iOS Access parent view elements from child viewiOS 从子视图访问父视图元素
【发布时间】:2014-08-08 13:28:49
【问题描述】:

我有一个 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 SettingsViewController 关闭屏幕。我是不是不懂亲子关系???

【问题讨论】:

    标签: ios uitableview performselector childviewcontroller parentviewcontroller


    【解决方案1】:

    废话,经过几个小时的尝试找到了答案...thanks to this

    if([self.parentViewController isKindOfClass:[SomeViewController class]]) {
        SomeViewController* viewController = (SomeViewController*)self.parentViewController;
        [viewController foo];
    }
    

    【讨论】:

      猜你喜欢
      • 2013-10-24
      • 2011-06-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多