Domanda

sto cercando di spingere un UIView opengl al mio controller di navigazione come questo

GraphViewController *gvc = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:gvc animated:YES];
[gvc release];

Il metodo initWithTicker assomiglia a questo

-(id) initWithTicker:(NSString*)ticker{
self = [super initWithNibName:nil bundle:nil];
if (self) {
    self.title = ticker;
    EAGLView *eagl = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    eagl.animationInterval = 1.0 / 60.0;
    [eagl startAnimation];
    self.view = eagl;
}
return self;

}

Quando vado indietro e avanti nella mia UINavigationController, il metodo drawView (in EAGLView) continua a loop. Inoltre, se mi pushViewController ancora una volta, viene creato il primo non si ferma e uno nuovo! Ho provato a fare questo una variabile di istanza in modo viene creato un solo ed ha lo stesso effetto. Le sarei grato se qualcuno ha comprensione quanto a perché questo sta accadendo

sergio Suggerimento:

-(id) initWithTicker:(NSString*)ticker{
   self = [super initWithNibName:nil bundle:nil];
   if (self) {
      self.title = ticker;
   }
   return self;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.

- (void)loadView {
    eagl = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.view = eagl;
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    eagl.animationInterval = 1.0 / 60.0;
    [eagl startAnimation];
    [super viewDidLoad];

}

stesso comportamento.

--- Ecco come ho fissato il mio drawView loop problema -

-(void)viewDidAppear:(BOOL)animated {
    [eagl startAnimation];
    [super viewDidAppear:animated];
}

-(void)viewDidDisappear:(BOOL)animated {
    [eagl stopAnimation];
    [super viewDidDisappear:animated];

}

- soluzione Craigs -

if(graphView == nil){
        graphView = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
    }else{
        [graphView release];
        graphView = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
    }
È stato utile?

Soluzione

Are you creating a new GraphViewController every time you want to push one onto your navigation stack? If so, it doesn't really matter how you're handling the creation of your EAGLView instance variable, since you're never going to be interacting with that view controller again anyway.

For example:

  1. User taps something, a new GraphViewController is pushed on the stack
  2. User goes back, this view controller continues to run
  3. Return to 1. and repeat (thus creating a SECOND GraphViewController, and then a third, and then a fourth... etc.)

What you should probably be doing is maintaining your GraphViewController as an instance variable, and only creating it once. This will ensure that you're in turn only creating one EAGLView.

if (_graphViewController == nil) {
    _graphViewController = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
}
[self.navigationController pushViewController:_graphViewController animated:YES];

Then, be sure to release the view controller in your dealloc method if you're going to be maintaining it as an ivar.

Altri suggerimenti

Would you try executing this code of yours:

EAGLView *eagl = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
eagl.animationInterval = 1.0 / 60.0;
[eagl startAnimation];
self.view = eagl;

inside of loadView? I am not sure about why your view is behaving like you say, but that is the place where you are supposed to build your UI... so it might make a difference...

Furthermore, I would call [eagl startAnimation]; only in viewDidLoad...

Hope it helps...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top