0

我正在尝试像这样将 opengl UIView 推送到我的导航控制器

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

initWithTicker 方法如下所示

-(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;

}

当我在 UINavigationController 中来回前进时,drawView 方法(在 EAGLView 中)一直在循环。此外,如果我再次 pushViewController,第一个不会停止并创建一个新的!我试过把它作为一个实例变量,所以只创建了一个并且它具有相同的效果。如果有人了解为什么会发生这种情况,我将不胜感激

塞尔吉奥建议:

-(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];

}

相同的行为。

---这就是我修复drawView循环问题的方法---

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

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

}

--Craigs解决方案--

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

2 回答 2

1

你会尝试执行你的这段代码:

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

里面loadView?我不确定为什么您的视图表现得像您说的那样,但那是您应该构建 UI 的地方......所以它可能会有所作为......

此外,我只会打电话[eagl startAnimation];viewDidLoad...

希望能帮助到你...

于 2011-11-30T20:57:14.127 回答
1

GraphViewController每次您想将一个推送到导航堆栈时,您是否都在创建一个新的?如果是这样,那么您如何处理实例变量的创建并不重要EAGLView,因为无论如何您都不会再次与该视图控制器进行交互。

例如:

  1. 用户点击某些东西,一个 GraphViewController的被压入堆栈
  2. 用户返回,这个视图控制器继续运行
  3. 返回到 1. 并重复(从而创建一个SECOND GraphViewController,然后是第三个,然后是第四个......等等)

您可能应该做的是维护您GraphViewController的实例变量,并且只创建一次。这将确保您反过来只创建一个EAGLView.

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

然后,如果您要将其维护为 ivar ,请确保release在您的方法中使用视图控制器。dealloc

于 2011-11-30T22:06:58.270 回答