开发者

Problem FBConnect (IPHONE), code not run on didLoad

Three days ago this code worked...:(

The label will not update to show the loaded facebook username.

//Interface .h
IBOutlet UILabel *namefb;  
...
@property(nonatomic, retain)UILabel *namefb;


//Implementation .m

- (void)request:(FBRequest*)request didLoad:(id)result {

        NSArray* users = result;

    NSDictionary* user = [users objectAtIndex:0];

    NSString* name = [user objectForKey:@"name"];

       namefb.text=[NSString stringWithFormat:@"Log-in: %@", name];//not update
}

(I have also connected the label in IB and importe开发者_高级运维d all fbconnect delegates )

When I run it in debug, the variable name is right, but namefb.text does not get updated..

Any ideas?

sorry for my english..:)


Your code assumes three things:

  1. The result object is of type NSArray.

  2. The NSArray has at least one object, which is an NSDictionary.

  3. That object has a key "name" that has an NSString object associated with it.

Test each of these three things, perhaps by using some NSLog() statements, and you should see where the problem is.


Make sure you connected namefb to a UILabel object in Interface Builder. Simply making that variable an outlet won't cause an object to appear there out of thin air—you need to create the object (in IB) and plug it into the outlet (in IB).

Until it's connected to an object, the variable will hold nil, and a message to nil does nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜