我正在使用 STTwitter API 来制作 App only twitter Feed。我已成功将推文输出到表格单元格,但现在我正在尝试连接用户个人资料图像,但遇到了一些问题。我尝试实现我在此处找到的代码,但我收到一条错误消息,指出“选择器'imageWithContentsOfURL:'没有已知的类方法”,所以我通过用 CIImage 替换 UIImage 解决了这个问题。但是,现在我的应用程序崩溃了,因为我试图将 CIImage 输出到 UIImageView。我的代码和错误如下:
代码:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* boldFontName = @"Avenir-Black";
[self styleNavigationBarWithFontName:boldFontName];
self.title = @"Twitter Feed";
self.feedTableView.dataSource = self;
self.feedTableView.delegate = self;
self.feedTableView.backgroundColor = [UIColor whiteColor];
self.feedTableView.separatorColor = [UIColor colorWithWhite:0.9 alpha:0.6];
//self.profileImages = [NSArray arrayWithObjects:@"profile.jpg", @"profile-1.jpg", @"profile-2.jpg", @"profile-3.jpg", nil];
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"stuff"
consumerSecret:@"stuff"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *username) {
[twitter getUserTimelineWithScreenName:@"RileyVLloyd"
successBlock:^(NSArray *statuses) {
self.twitterDataSource = [NSMutableArray arrayWithArray:statuses];
for (int i=1; i <= _twitterDataSource.count; i++) {
NSLog(@"%d", i);
NSDictionary *tweetDictionary = self.twitterDataSource[i];
NSString *final = tweetDictionary[@"profile_image_url"];
NSLog(@"%@", final);
}
[self.feedTableView reloadData];
} errorBlock:^(NSError *error) {
NSLog(@"%@", error.debugDescription);
}];
} errorBlock:^(NSError *error) {
NSLog(@"%@", error.debugDescription);
}];
//[self getTimeLine];
}
#pragma mark Table View Methods
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.twitterDataSource.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"FeedCell3" ;
FeedCell3 *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
if (cell == nil) {
cell = [[FeedCell3 alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
}
cell.nameLabel.text = @"RileyVLloyd";
cell.likeCountLabel.text = @"293 likes";
cell.commentCountLabel.text = @"55 comments";
//NSString* profileImageName = self.profileImage[indexPath.row%self.profileImage.count];
cell.profileImageView.image = _profileImage;
NSInteger idx = indexPath.row;
NSDictionary *t = self.twitterDataSource[idx];
cell.updateLabel.text = t[@"text"];
cell.dateLabel.text = @"1 day ago";
return cell;
}