顺便说一句,你想在一张桌上显示用户在其装置上的垂直账户。 你很可能想在桌子上显示瓦tar,在这种情况下,你需要询问Twitter的图像。
假设您的密码>,>ACAccount
物体,您可设立一个词典,为每个账户储存额外信息。 页: 1 我们需要这样的一些法典:
// Assuming that you ve dequeued/created a UITableViewCell...
// Check to see if we have the profile image of this account
UIImage *profileImage = nil;
NSDictionary *info = [self.twitterProfileInfos objectForKey:account.identifier];
if (info) profileImage = [info objectForKey:kTwitterProfileImageKey];
if (profileImage) {
// You ll probably want some neat code to round the corners of the UIImageView
// for the top/bottom cells of a grouped style `UITableView`.
cell.imageView.image = profileImage;
} else {
[self getTwitterProfileImageForAccount:account completion:^ {
// Reload this row
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}];
}
All this is doing is accessing a UIImage
object from a dictionary of dictionaries, keyed by the account identifier and then a static NSString
key. If it doesn t get an image object, then it calls an instance method, passing in a completion handler block, which reloads the table row. The instance methods looks a bit like this:
#pragma mark - Twitter
- (void)getTwitterProfileImageForAccount:(ACAccount *)account completion:(void(^)(void))completion {
// Create the URL
NSURL *url = [NSURL URLWithString:@"users/profile_image" relativeToURL:kTwitterApiRootURL];
// Create the parameters
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
account.username, @"screen_name",
@"bigger", @"size",
nil];
// Create a TWRequest to get the the user s profile image
TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
// Execute the request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
// Handle any errors properly, not like this!
if (!responseData && error) {
abort();
}
// We should now have some image data
UIImage *profileImg = [UIImage imageWithData:responseData];
// Get or create an info dictionary for this account if one doesn t already exist
NSMutableDictionary *info = [self.twitterProfileInfos objectForKey:account.identifier];
if (!info) {
info = [NSMutableDictionary dictionary];
[self.twitterProfileInfos setObject:info forKey:account.identifier];
}
// Set the image in the profile
[info setObject:profileImg forKey:kTwitterProfileImageKey];
// Execute our own completion handler
if (completion) dispatch_async(dispatch_get_main_queue(), completion);
}];
}
因此,确保你不屈不.,但随后在下载简介图像时将更新表格。 在你完成学业时,你可以把他们放在形象的十字架上,否则就将他们延续到阶级的寿命之后。
也可使用同样的程序获取其他“Twitter”用户信息:。