我很难弄清楚如何把这些放在一起.我在mac上有一个解谜应用程序.你进入拼图,按一个按钮,当它试图找到解决方案的数量,min移动,这样我想保持UI更新.然后,一旦完成计算,重新启用按钮并更改标题.
下面是一些来自按钮选择器的示例代码,以及解决功能:(请记住,我从Xcode复制/粘贴,因此可能会有一些丢失{}或其他一些错别字...但它应该让你知道我的意思我想做.
基本上,用户按下按钮,该按钮是ENABLED = NO,函数调用来计算拼图.在计算时,请使用移动/解决方案数据更新UI标签.然后,一旦完成计算拼图,Button就会被启用= YES;
按下按钮时调用:
- (void) solvePuzzle:(id)sender{
solveButton.enabled = NO;
solveButton.title = @"Working . . . .";
// I've tried using this as a Background thread, but I can't get the code to waitTilDone before continuing and changing the button state.
[self performSelectorInBackground:@selector(createTreeFromNode:) withObject:rootNode];
// I've tried to use GCD but similar issue and can't get UI updated.
//dispatch_queue_t queue = dispatch_queue_create("com.gamesbychris.createTree", 0);
//dispatch_sync(queue, ^{[self createTreeFromNode:rootNode];});
}
// Need to wait here until createTreeFromNode is finished.
solveButton.enabled=YES; …Run Code Online (Sandbox Code Playgroud)