【发布时间】:2013-03-31 22:48:51
【问题描述】:
我是 iOS 新手,我需要一些关于如何在 Iphone 屏幕上无限循环显示输出的反馈。
按下按钮时,应用程序进入无限循环并创建一些输出。我想在 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 线程以显示在屏幕上。文档中有一个线程编程指南 (developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/…) 可能会有所帮助
标签: ios loops text label infinite