简体   繁体   中英

How to navigate from UIView subclass to other UIViewController

Small issue again. First of all I've found here this brilliant battle of intellect , but alas there there's even no accepted answer. And other postings as well. Well, I need to navigate from UIView to other UIViewController.

My code: In -layoutSubviews I create a button

if(!setQualityButton)
{
    setQualityButton=[[[UIButton alloc]initWithFrame:CGRectMake(120.00,367.00,100,27)] autorelease];
    [self.setQualityButton setBackgroundImage:[UIImage imageNamed:@"btnGreen.png"] forState:UIControlStateNormal];

    [setQualityButton.layer setBorderColor: [[UIColor grayColor] CGColor]];
    [setQualityButton.layer setBorderWidth: 1.0];
    [setQualityButton.layer setCornerRadius:8.0f];
    [setQualityButton.layer setMasksToBounds:YES];

    [setQualityButton addTarget:self action:@selector(goToSetQualityView) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:setQualityButton];
}

And the method as himself

-(void)goToSetQualityView
 {
   SetQualityView *sqv=[[SetQualityView alloc]initWithNibName:@"SetQualityView" bundle:nil];
   sqv.itemID=self.itemID;
   sqv.currentQuality=theItem.quality;
   [[[[self window] rootViewController] navigationController] pushViewController:sqv animated:YES];
   [sqv release];
 }

When I push this button, nothing happens. I mean I do not get navigated to other view and no warnings.

Make viewcontroller that holds this view delegate of it and push next viewcontroller from it. Ot just supply navigation controller of viewcontrooler that holds view to it, so it will use it to puash next viewcontroller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM