问题 FBConnect (IPHONE),代码未在 didLoad 上运行
三天前这段代码有效...:(
标签不会更新以显示加载的facebook用户名。
//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
}
(我还在IB中连接了标签并导入了所有fbconnect委托)
当我在调试中运行它时,变量名称是正确的,但是 namefb.text 没有更新..
有什么想法吗?
对不起我的英语..:)
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 imported 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..:)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的代码假设三件事:
result
对象的类型为NSArray
。NSArray
至少有一个对象,它是一个NSDictionary
。该对象有一个键“name”,该键有一个与之关联的
NSString
对象。或许通过使用一些
NSLog()
语句来测试这三件事中的每一个,您应该会看到问题出在哪里。Your code assumes three things:
The
result
object is of typeNSArray
.The
NSArray
has at least one object, which is anNSDictionary
.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.确保您已将
namefb
连接到 Interface Builder 中的 UILabel 对象。简单地将该变量设置为插座不会导致对象凭空出现 - 您需要创建该对象(在 IB 中)并将其插入插座(在 IB 中)。在连接到对象之前,该变量将保存
nil
,并且发送给nil
的消息不会执行任何操作。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 tonil
does nothing.