我有一个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.在运行performSelector
DOES日志时在VC1方法中添加日志语句但该方法的其余部分不运行,不会将SettingsViewController从屏幕上滑下来。我不理解父/子关系???
答案 0 :(得分:1)
废话,经过几个小时的尝试后找到答案... thanks to this
if([self.parentViewController isKindOfClass:[SomeViewController class]]) {
SomeViewController* viewController = (SomeViewController*)self.parentViewController;
[viewController foo];
}