iPhone: can i have a solution for converting NSNumber into NSString
hi i am working for Twitter client, i want display number(NSNumber) on UILabel like follower count, tweet, friends counts etc
this is delegate to store user Profile Data in NSArray it contains all info like user name and screen name and no. of followers, messages, status count, following this detail i have to display on respective Labels
- (void)userInfoReceived:(NSArray *)userInfo
forRequest:(NSString *)connectionIdentifier
{
NSLog(@"开发者_StackOverflow社区User Info Received: %@", userInfo);
NSMutableDictionary *profileData = [userInfo objectAtIndex:0];
// userInfo is converted into NSDictionary
lblUserName.text = [profileData objectForKey:@"name"];
// user name is displaying on lblUserName UILabel
and here lblUserName
- UILabel
, profileData
- NSDictionary
, userInfo
- NSArray
On UILabel i have to display user follower count no
how i have to work with this
[NSNumber stringValue]
is good
You should use stringWithFormat
which behaves similar to printf. That is, you can pass a string with placeholders that are interpolated.
NSNumber *number = [NSNumber numberWithInt:100];
NSString *string = [NSString stringWithFormat:@"%d followers", [number intValue]];
NSLog(@"%@", string); // Would print "100 followers\n"
You should use [NSString stringWithFormat]
NSNumber has an instance method called integerValue, which can convert an NSNumber object into a NSInteger. Then you can use NSString's stringWithFormat to convert that NSInteger into an autoreleased NSString.
精彩评论