سؤال

I have a function call and some coding statements after the function. These statements should be called only after the function is executed completely How can it be achieved? Currently the statements are executed before the function is executed completely.

For example

NSInteger integerRestValue=[self buttonRestNameTag];
buttonRestNames.titleLabel.text=[[arrayGuessList objectAtIndex:integerRestValue]valueForKey:@"Name"];

Here the buttonRestNameTag function is called and before the execution is completed the buttonRestNames title label is set which cause it to crash.

How can this be resolved?

هل كانت مفيدة؟

المحلول

You may have initialized another Thread inside your function buttonRestNameTag. Check that thing.

Or Try to use this function :

[self performSelectorOnMainThread:@selector(functionName) withObject:nil waitUntilDone:YES];

Hope this helps.

Edit for Kiron :

Make a variable in class and put returned value in that and access that variable.

This is helpful link to do this

iphone - performSelectorOnMainThread with return value

نصائح أخرى

You can use GCD blocks Try this.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top