开发者

Calling method from another class

To begin, I would like to apologize for my English :)

I have FirstViewController, which contains scrollView. This is scrolView with enabled paging, and have 2 pages with 2 different view controllers. From one of the view controllers by touchin开发者_Python百科g the button the third view controller appears like a modal view. I call a method in FirstViewController that must disable scrolling and hide two labels which is not contained in the scrollView. Method is executing, but UI not changes, scrolling still enabled and labels still visible.

Now a bit of code:

This is a piece of the FirstViewController.h (not the whole code):

@interface FirstViewController : UIViewController <UIScrollViewDelegate> {

    IBOutlet UIScrollView *scrollView;
    IBOutlet UILabel *label1;
    IBOutlet UILabel *label2;

}

@property (nonatomic, retain) UILabel *label1;
@property (nonatomic, retain) UILabel *label2;
@property (nonatomic, retain) UIScrollView *scrollView;

-(void)prepareToModal;


@end

Now it's -(void)prepareToModal; implementation:

-(void)prepareToModal {
    [label1 setHidden:YES];
    [label2 setHidden:YES];
    scrollView.scrollEnabled = NO;
}

So, from the one of the view controllers, which contained in scrollView, I call prepareToModal

Previously:

#import "FirstViewController.h"

Next:

FirstViewController *vc = [[FirstViewController alloc] init];
[vc prepareToModal];
[vc release];

So, that's all. I put a breakpoint in prepareToModal, and it stopped executing. The method is called, but nothing changes on screen...

What am I doing wrong? How to do this correctly?

Update:

I solved this problem.

When I present this modal view, I wrote this:

ThirdViewController *tvc = [[ThirdViewControler alloc] init];
tvc.delegate  = self;

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:tvc];

[self presentModalViewController:nc animated:YES];

[tvc release];
[nc release];

Now, insted of [self presentModalViewController:nc animated:YES]; I write this:

[[[[UIApplication sharedApplication].windows objectAtIndex:0] rootViewController] presentModalViewController:nc animated:YES];

And It's working very well, I don't need a method -(void)prepareToModal;

Thanks a lot :)


Make sure you have hooked up your IBOutlets in Interface Builder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜