Iphone UINavigationController并推送openGL UIView=永无止境的循环

Iphone UINavigationController并推送openGL UIView=永无止境的循环,iphone,opengl-es,uinavigationcontroller,eaglview,Iphone,Opengl Es,Uinavigationcontroller,Eaglview,我正试图像这样将opengl UIView推送到我的导航控制器 GraphViewController *gvc = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]]; [self.navigationController pushViewController:gvc animated:YES]; [gvc release]; -(id) initWithTicker:(

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

GraphViewController *gvc = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:gvc animated:YES];
[gvc release];
-(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;
initWithTicker方法如下所示

GraphViewController *gvc = [[GraphViewController alloc] initWithTicker:[listOfItems objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:gvc animated:YES];
[gvc release];
-(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中)会不断循环。此外,如果我再次推视图控制器,第一个不会停止,并且创建新的!我已经尝试将其作为一个实例变量,因此只创建一个实例变量,并且它具有相同的效果。如果有人能洞悉为什么会发生这种情况,我将不胜感激

塞尔吉奥建议:

-(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循环问题的方法--

--克雷格斯溶液--


请尝试执行您的以下代码:

EAGLView *eagl = [[EAGLView alloc] initWithFrame:[UIScreen mainScreen].bounds];
eagl.animationInterval = 1.0 / 60.0;
[eagl startAnimation];
self.view = eagl;
加载视图的内部
?我不知道为什么您的视图会像您所说的那样运行,但这是您应该构建UI的地方。。。所以这可能会有不同

此外,我将调用
[eagl startAnimation]仅在
viewDidLoad


希望它有帮助……

您是否每次都要在导航堆栈中添加一个新的
图形控件?如果是这样,那么如何处理
EAGLView
实例变量的创建实际上并不重要,因为无论如何,您都不会再与该视图控制器交互

例如:

  • 用户点击某个内容,就会在堆栈上推送一个新的
    图形视图控制器
  • 用户返回时,此视图控制器继续运行
  • 返回到1。并重复(从而创建第二个
    图形视图控制器
    ,然后是第三个,然后是第四个…等等)
  • 您可能应该做的是将
    GraphViewController
    作为实例变量进行维护,并且只创建一次。这将确保您依次创建一个
    eagleView

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

    然后,如果要将视图控制器作为ivar进行维护,请确保在
    dealloc
    方法中
    release
    视图控制器。

    请参阅我的编辑。不幸的是,同样的行为..视图控制器只是继续堆叠,最终使程序崩溃
    startAnimation
    是如何定义的?如果你把它注释掉会发生什么?问题是我需要一个graphViewController来处理每个股票代码字符串,比如说20,所以一旦定义了它,它就变成了!=nil,因此每次我将它推到堆栈上时都使用相同的graphViewController。但是,我可能能够将这些GraphViewController存储在NSMutableDictionary中,并使用ticker作为键。让我试试,然后再报告。非常感谢!:)如果没有你的应用程序的细节,我们只能推测,但听起来你需要重新设计一些东西——要么为股票代码字符串添加一个setter(如果你一次只显示一个GraphViewController),要么像你提到的那样,保留一个以股票代码为键的字典。谢谢你的及时回复craig。我愿意辞职--让我简单地告诉你我想做什么。我有一个导航视图控制器,它有一个带表的RootViewController。该表包含几个常用字符串。现在让我们说RIMM,APPL,GOOG。当按下一个按钮时,它将使用initWithTicker方法加载GraphViewController,并将无NIBLES openGL视图(EAGLVIEW)与该控制器关联。在OpenGL视图中有一个drawView方法,它可以在屏幕上绘制图形。正如您所知,此循环从未停止过。听起来您可能希望将GraphViewController上的ticker字符串设置为“可设置”。也就是说,在将视图控制器推到屏幕上之前,您可以设置ticker字符串:
    vc.tickerString=@“RIMM”或类似。这样,您只需要一个视图控制器。(这将节省您的内存、计算时间等)是的,如果这对您有效,应该没问题。不确定纵向/横向问题是怎么回事,但我建议您在Instruments中评测应用程序,以确保不会在任何地方泄漏内存。