English 中文(简体)
睡觉时有客观的眼光。
原标题:in objective-c, sleep happens before code prior to it

在这项法典中,似乎睡觉发生在藏匿纽州之前。 为什么如此?

-(void)buttonPressed{
        NSLog(@"Button pressed!");
        button.hidden=true;
        sleep(rand()%10);
        NSLog(@"out of sleep!");
    }
问题回答

隐蔽的设置立即发生,并触发了一条滚.的<条码>。 然后该方法睡觉。 然后在睡觉后,露骨会铺设,显示器具更新。 因此,在睡觉结束之前,睡觉才阻止放映。

我的猜测是,hidden property是成功确定的,但该屏幕是经过更新的,因为你穿透了胎面。

随后将进行筛查更新。

I don t have any specific objective-c knowledge on this point - but it is a common case that UI is single threaded and that the update of your button state is put on a queue for execution. The call to sleep then suspends all current thread activity and therefore halts UI updating.

证券交易所基本上树立了旗帜,将使得控制权在万国证券交易所的下一个时间重新投放。 它立即取得成效,因为它通常会稍微推迟,以便各种家庭单元的复习能够共同进行。

如果你在躲藏你的ton子后想采取某些行动,那么,我建议打电话<条码>performSelector:有目标:继:。

How to use performSelector:withObject:afterDelay: with primitive types in Cocoa?

In general, you want to have the UI thread block as little as possible, as any blocking code (e.g. sleep) will cause the UI to lag, be generally unresponsive, or beach-ball (SPoD).





相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签