我用编程代码创建了一个UIScrollView
,我的视图中有一个按钮(在 中不存在UIScrollView
)。
当我单击此按钮时,转到具有模态转换的下一页。我在下一页创建取消按钮,当我单击它返回主页时(此页面有UIScrollView
)。
我想在单击“取消”按钮并返回主页时调用主页中的一种方法,并在此方法中更改ContentOfSet
我的 ScrollView ......但不工作!!!!
这是我的代码:
主视图.m
- (void)viewDidLoad{
UIScrollView *scrollbar = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,width, height)];
scrollbar.directionalLockEnabled = YES;
scrollbar.backgroundColor = [UIColor whiteColor];
scrollbar.maximumZoomScale = 1.0;
scrollbar.minimumZoomScale = 1.0;
scrollbar.clipsToBounds = YES;
scrollbar.showsHorizontalScrollIndicator = YES;
scrollbar.pagingEnabled = YES;
[scrollbar setContentSize:CGSizeMake(scrollbar.frame.size.width * 4,scrollbar.frame.size.height)];
scrollbar.contentOffset = CGPointMake(0, 0);
scrollbar.delegate = self;
[self.view addSubview:scrollbar];
[super viewDidLoad];
}
-(void)ChangeMainScrollContentOffset{
scrollbar.contentOffset = CGPointMake(scrollbar.frame.size.width * (3), 0);
}
此按钮位于根视图中:
- (IBAction)AddView:(id)sender{
AddStationController *add = [[AddStationController alloc]initWithNibName:@"AddStationController" bundle:nil];
[add setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self.view.window.rootViewController presentViewController:add animated:YES completion:nil];
}
这个按钮是取消按钮,用于在我的主视图中返回:
- (IBAction)BackView:(id)sender{
mainView *main = [[mainView alloc]init];
[main ChangeMainScrollContentOffset];
[self dismissViewControllerAnimated:YES completion:nil];
}
请指导我!我很困惑为什么不工作 ContentOffSet !!!