开发者

Set Delegate methods on child view controll

开发者 https://www.devze.com 2023-02-22 07:24 出处:网络
I am building an application which should allow the user to scroll through the images. Since I have many images (downloaded from the web), what i doing is I have UP and down button on the parent view,

I am building an application which should allow the user to scroll through the images. Since I have many images (downloaded from the web), what i doing is I have UP and down button on the parent view, in addition i have the scroll view. Based on the selected option (up or down), I add the ImageClass ( created a class which extends UIViewController) view to the scroll view.

Now, on the selected view the user can mark a point or do any stuff.

The question is how from the parent view I can call methods of the Uiviewcontroller. I know how I can set the delegate methods but what I want is that parent controller can call any a method say redraw method which would redraw the entire view.

Code:

-(IBAction) down:(id) sender{

    [scrollView2 removeFromSuperview];

}

-(IBAction) down        :(id) sender {

    [scrollView2 removeFromSuperview];
    if(scrollView2 == nil)
        scrollView2 = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView2];
    [self.view sendSubviewToBack:scrollView2];
    [scrollView2 setBackgroundColor:[UIColor blackColor]];
    [scrollView2 setCanCancelContentTouches:NO];
    scrollView2.clipsToBounds = YES; 开发者_如何学Python   
    // default is NO, we want to restrict drawing within our scrollview

    scrollView2.indicatorStyle = UIScrollViewIndicatorStyleWhite;

    // CSImageView is a class which of the type UIViewController
    imageVie = [[CSImageView alloc] init];
    [scrollView2 addSubview:imageVie.view];
    [scrollView2 setContentSize:CGSizeMake(1500,1500)];
    [scrollView2 setScrollEnabled:YES];
    [imageView release];
}

Now, from the parent view controller I want to call say:

imageVie.redraw(); method

Code for CSImageView

@interface CSImageView : UIViewController {

    NSNumber *imageId ;

}

@property (nonatomic, retain) NSNumber *venueId;

-(void) redraw;
@end


@implementation CSImageView


@synthesize imageId;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


-(void) redraw {
    NSLog(@"I am ehre in the test function");
}
@end

Can you please help me on the same. I am not able to call the redraw method. Any input would be appreciated.


First, CSImageView should probably be a subclass of UIView, not UIViewController. You should keep a reference to your instance (i.e. as an instance variable or synthesized property) so you can access it from methods other than - down:.


Wow.

I can't say I follow what you've coded, but here's how you do it.

During this part...add a tag to the view

// CSImageView is a class type UIViewController
imageVie = [[CSImageView alloc] init];
imageVie.tag = 99 // Any number. Preferably a constant
[scrollView2 addSubview:imageVie.view]; ...

Then on the parent

view controller. You can ...

-(IBAction) down:(id) sender {

CSImageView *view = [scrollView2 viewWithTag:99];
[view redraw]; 

... }

Something like that.

0

精彩评论

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