我正在使用STTwitter API来制作一个仅限应用程序的twitter。我已经成功地将tweet输出到表单元格中,但是现在我试图连接用户配置文件图像,并且遇到了一些问题。我尝试实现我找到的这里代码,但是我遇到了一个错误:“选择器‘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;
}发布于 2014-05-07 05:18:58
实现这一目标的一种更简单的方法是使用SDWebImage API。API异步加载映像,因此您不必担心加载,因为主线程用于加载映像。此外,这个API只需要将下面的几行代码添加到UITableViewCell方法中。
NSString *aURL = t[@"user"][@"profile_image_url"];
[cell.profileImageView setImageWithURL:[NSURL URLWithString:aURL]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]];发布于 2014-05-06 11:37:23
您的代码确实崩溃了,因为您试图为键profile_image_url在username上获取一个值,它是一个字符串,因此是异常<__NSCFString ...> is not key value coding-compliant for the key profile_image_url。
让我们假设您真正想要做的是检索每个推特作者的图片。
您必须迭代这些状态,并对每个状态提取profile_image_url并使用它创建一个UIImage。
https://stackoverflow.com/questions/23484787
复制相似问题