我試圖把一個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