objective c - iPhone SDK: viewDidLoad() sees an empty NSArray, but it's populated in a delegate method (MGTwitterEngine) -


This is probably obvious, but I'm a little of a newbie and have spent hours understanding it.

I have a function on an MGTwitterEngine object (custom object) with an input in viewDidLoad (). If the request (on Twitter, in this case) is successful, then it calls a proper representative method

In viewDidLoad (), it is like this:

  [ MyTwitterEngine getSearchResultsForQuery: @ "#cotation" sinceID: 0 startup page: 0 count: 10];  

In the case of a successful search request the caller's representative method looks like this:

  - (zero) searchResults received: (NSArray * ) Search for searchResest: (NSString *) Connection identifier {NSMutableArray * tempArray = [[[NSMutableArray alloc] init] autorelease]; If ((calculation of search results)> 0) {for (int n = 0; n  

I can not understand this: Finally, where I say "Ok, the work is here", it is clear that the self The message (an NSArray) is populated with information that I want

However, if I call it again in the viewdidoad () after the first method, then self.messages are empty I have done it in the seen. DIDLoad ():

  [myTwitterEngine getSearchResultsForQuery: @ "#cotation"]; NSLog (@ "before or after \")? NSLog (@ "Viewedload from:% @", [[Self Message ObjectAt Express: 13] The Message]);  

The results are strange before NSLog results come before the results of the representative method. Here is the console output:

  2009-12-05 23: 15: 20.758 Anandru [54463: 207] Before or after? 2009-12-05 23: 15: 20.761 Anandru [54463: 207] From view deedload: (empty) 2009-12-05 23: 15: 21.005 Indru [54463: 207] Successful for request connection = 92B2E7EC-AA2F- 4301-812E -E8E5AEAF7035 2009-12-05 23: 15: 21.007 Anandru [54463: 207] By Representative Method: RT @ThenkPlanauts: RT @Felikelom I usually take more than three weeks to prepare a good excitement speech. Mark Twain # Quote  

Eventually I want to use array messages as a data source for a table. How can I use this variables from within the delegate method elsewhere in the implementation?

Does anyone know why the representative represents the output from the method finally comes, though I have called the actual function before or after the NSLog?

Any help appreciated!

I do not know anything from MGTwitterEngine, but clearly -getSearchResultsForQuery: An asynchronous way; It will return immediately and your representative will call the method some time after the results are available.

Your array is empty in -viewDidLoad because the results are not yet received. Additionally, your array always -viewDidLoad Will be empty because your representative method can not be called until you control your run loop.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -