获取错误设置UIButton的标题

时间:2013-11-27 15:08:51

标签: ios iphone objective-c twitter uibutton

我尝试从twitter发出特定UIButton的{​​{1}}收藏计数。我可以在功能上获得这个数字,我已成功通过Twitter授权。以下是我尝试设置标题的方法:

tweet

当我运行此操作时,我在 //Set number of Favorites for Tweet NSObject *favoritesCount = [[tweet objectForKey:@"user"]objectForKey:@"favourites_count"]; UIButton *favoritesButton = (UIButton *)[cell viewWithTag:204]; favoritesButton.titleLabel.text = favoritesCount;

处收到错误消息

以下是我遇到的错误:

favoritesButton.titleLabel.text = favoritesCount;

1 个答案:

答案 0 :(得分:2)

标题应为NSString值。您需要将标题设置为NSString而不是NSObject。

    NSInteger favoritesCount = [[tweet objectForKey:@"user"]objectForKey:@"favourites_count"];
    UIButton *favoritesButton = (UIButton *)[cell viewWithTag:204];
    favoritesButton.titleLabel.text = [NSString stringWithFormat:@"%d",favoritesCount];