我试图把一个OpenGL的UIView我的导航控制器这样的UINavigationController,推动一个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函数problem--循环
-(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]];
}
问题是我需要一个graphViewController用于每个ticker字符串,这可能是20,所以一旦它被定义,它就变成!= nil,因此每次我将它推入堆栈时都会使用相同的graphViewController。但是,我可能能够将这些graphViewController存储在一个NSMutableDictionary中,并以ticker作为关键字。让我试试并回报。非常感谢! :) – Submerged
没有你的应用程序的细节,我们只能推测,但它听起来像你需要重新设计一些东西 - 要么为ticker字符串添加一个setter(如果你一次只显示一个GraphViewController),或者如你所说,以股票作为关键字保存字典。 –
感谢您的快速响应craig。我愿意辞职 - 让我简单地了解我想要做的事情。我有一个导航视图控制器,它有一个带有表格的RootViewController。该表包含多个股票字符串。现在让我们说RIMM,APPL,GOOG。当按下某个按钮时,它会使用initWithTicker方法加载GraphViewController,并将Nibless openGL视图(EAGLVIEW)与该控制器相关联。在那个OpenGL视图里面是一个drawView方法,它将图形绘制到屏幕上。如你所知,这个循环从未停止。 – Submerged