Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS delegate issues with KVO
    text
    copied!<p>I have a method which sends out a request and has a delegate responder. The method is being called by a KVO responder. The code works fine when I call it from viewDidLoad, but when I make the request from the KVO method, it doesn't trigger the delegate method.</p> <p>here is my KVO responder:</p> <pre><code>//observe app delegates userdata to check for when user data is available or data is changed - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"userData"] ) { //goto facebook logic [self FBFriendSuggester]; } } </code></pre> <p>and the method it calls:</p> <pre><code>-(void)FBFriendSuggester { NSDictionary * fb_credentials = nil; if([prefs objectForKey:@"facebookCredentials"]) { fb_credentials = [prefs objectForKey:@"facebookCredentials"]; if ([fb_credentials objectForKey:@"expiry"] &amp;&amp; [fb_credentials objectForKey:@"fbtoken"]) { NSLog(@"found stored Facebook credentials."); ApplicationDelegate.facebook.accessToken = [fb_credentials objectForKey:@"fbtoken"]; ApplicationDelegate.facebook.expirationDate = [fb_credentials objectForKey:@"expiry"]; } } if ([ApplicationDelegate.facebook isSessionValid]) { printf("_valid facebook\n"); [ApplicationDelegate.facebook requestWithGraphPath:@"me/friends" andDelegate:self]; }else printf("_invalid facebook\n"); } </code></pre> <p>and the delegate method:</p> <pre><code>- (void)request:(FBRequest *)request didLoad:(id)result{ NSLog(@"result2:%@",result); NSDictionary * rawObject = result; NSArray * dataArray = [rawObject objectForKey:@"data"]; for (NSDictionary * f in dataArray) { [friends addObject:[[KNSelectorItem alloc] initWithDisplayValue:[f objectForKey:@"name"] selectValue:[f objectForKey:@"id"] imageUrl:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=square", [f objectForKey:@"id"]]]]; } [friends sortUsingSelector:@selector(compareByDisplayValue:)]; [self pickerPopup:self]; } </code></pre> <p>the delegate method doesn't get called in this scenario, but it does work fine when i call -(void)FBFriendSuggester directly from the controller. I don't know what to do, i tried setting a notification to respond in hopes that it would trigger the delegate, but that didn't work either.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload