我是iOS新手,我需要一些關於如何在無限循環中在Iphone屏幕上顯示輸出的反饋。在無限循環中顯示輸出iOS
當按鈕被按下時,應用程序進入無限循環並創建一些輸出。我想在Iphone屏幕上顯示這些輸出。儘管我在調試屏幕上從printf中獲取這些值,但是在Iphone屏幕上沒有任何顯示。如果我想在沒有無限循環的情況下嘗試這個函數,我將能夠在屏幕上看到輸出,但是應用程序必須以無限循環運行。
因爲我對編程還很陌生,應用程序是否需要在多線程模式下運行?
的代碼如下:
-(IBAction)button:(UIButton *)sender{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int output = -1;
while (pool) {
//output is received
if((output != -1)) {
printf("%i \n", output); // the output is seen on debug screen
self.display.text = [NSString stringWithFormat:@"%i",output]; // the outputs is not shown on iphone
//[pool release];
}
}
}
是的,您需要在另一個線程上運行循環,並將結果發佈到UI線程以顯示在屏幕上。有關可能有用的文檔的線程編程指南(https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html) – Marcelo 2013-04-09 13:42:06