gpt4 book ai didi

iOS 从 subview 访问父 View 元素

转载 作者:行者123 更新时间:2023-11-29 02:45:24 25 4
gpt4 key购买 nike

我有一个 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];

添加设置时,我不会从父 View 中删除 ViewController1。当我用按钮切换设置 View 时,它就在侧面并滑入。在 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。在运行 performSelector 时在 VC1 方法中添加一个日志语句 DOES日志,但该方法的其余部分不会运行,不会将 SettingsViewController 滑出屏幕。难道是我不懂亲子关系???

最佳答案

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

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

关于iOS 从 subview 访问父 View 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25204666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com