Reputation: 317
Jest I tried programmatically ScrollView
. It's working nice in ViewController.m
I tried like this
scroll=[[UIScrollView alloc]init];
scroll.frame=CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height);
scroll.delegate=self;
scroll.scrollEnabled=YES;
scroll.contentSize =CGSizeMake(100, 525);
scroll.backgroundColor=[UIColor yellowColor];
[self.view addSubview:scroll];
goo=[[UIButton alloc]init];
goo.frame=CGRectMake(0, 50, 100, 100);
goo.backgroundColor= [UIColor brownColor];
[goo setTitle:@"good Day" forState:UIControlStateNormal];
[goo addTarget:self action:@selector(ok:) forControlEvents:UIControlEventTouchDown];
[scroll addSubview:goo];
Working Nice but same code is not working in SecondViewControl
-(void)ok:(id)sender
{
Second *second=[[Second alloc]initWithNibName:nil bundle:nil];
[second setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:second animated:YES completion:nil];
}
Second.m
scroll=[[UIScrollView alloc]init];
scroll.frame=CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height);
scroll.delegate=self;
scroll.scrollEnabled=YES;
scroll.contentSize =CGSizeMake(100, 525);
scroll.backgroundColor=[UIColor yellowColor];
[self.view addSubview:scroll];
I don't understand why scrollView
not working in Second.m
but same code working on ViewControl.m.
My Xcode Version 6.0.1
Upvotes: 0
Views: 117
Reputation: 593
Check the Following Steps:
Do you conform to UIScrollViewDelegate
in your second class.
If not set , the code scroll.delegate=self;
will cause problem.
Upvotes: 0
Reputation: 1491
Please use presentViewController
instead of modalViewController
and set the Delegate of UIScrollView
to SecondViewController
Upvotes: 1