我正试图在集合视图中显示Twitter源。我能够在普通的表格布局中显示twitter feed,但是当我尝试在集合视图中显示它时,我的视图控制器中没有显示任何内容。我拖着一个视图到我的视图控制器和视图收集到我的view.Here是我的故事板视图:无法在我的视图控制器中看到集合视图
viewcontroller->View-> View1 ->CollectionView -> CollectionViewCell-> Label,ImageView
在这里,我有我的视图控制器两种观点。一个是我的列表视图,另一个是收集视图。 我不确定我在这里错过了什么。你能帮我解决这个问题吗?
在此先感谢。 这里是我的文件:
TweetCell.h
#import <UIKit/UIKit.h>
@interface TweetCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UIImageView *imageTweet;
@property (weak, nonatomic) IBOutlet UILabel *textTweet;
@end
TweetCell.m
#import "TweetCell.h"
@implementation TweetCell
@synthesize textTweet,imageTweet;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"CellID" owner:self options:nil];
if ([arrayOfViews count] < 1) {
return nil;
}
if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
return nil;
}
self = [arrayOfViews objectAtIndex:0];
}
return self;
}
@end
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>{
IBOutlet UICollectionView *collectionViewTwitter;
}
@end
ViewController.m
#import "ViewController.h"
#import "STTwitter.h"
#import "TweetCell.h"
@interface ViewController()
@property (strong, nonatomic) NSMutableArray *twitterFeedList;
@end
- (void)viewDidLoad
{
[super viewDidLoad];
/* uncomment this block to use subclassed cells */
[self->collectionViewTwitter registerClass:[TweetCell class] forCellWithReuseIdentifier:@"cvCell"];
/* end of subclass-based cells block */
// Configure layout
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayout setItemSize:CGSizeMake(200, 200)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
[self->collectionViewTwitter setCollectionViewLayout:flowLayout];
STTwitterAPI *twitter = [STTwitterAPI twitterAPIAppOnlyWithConsumerKey:@"xz9ew8UZ6rz8TW3QBSDYg"
consumerSecret:@"rm8grg0aIPCUnTpgC5H1NMt4uWYUVXKPqH8brIqD4o"];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
[twitter getUserTimelineWithScreenName:@"MYTwitterUserName"
successBlock:^(NSArray *statuses) {
self.twitterFeedList = [NSMutableArray arrayWithArray:statuses];
[self->collectionViewTwitter reloadData];
} errorBlock:^(NSError *error) {
NSLog(@"%@", error.debugDescription);
}];
} errorBlock:^(NSError *error) {
NSLog(@"%@", error.debugDescription);
}];
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.twitterFeedList.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID = @"CellID" ;
NSInteger idx = indexPath.row;
NSDictionary *t = self.twitterFeedList[idx];
/* Uncomment this block to use subclass-based cells */
TweetCell *cell = (TweetCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
cell.textTweet.adjustsFontSizeToFitWidth=YES;
cell.textTweet.numberOfLines=4;
cell.textTweet.text=t[@"text"];
cell.imageTweet.image=[UIImage imageNamed:@"twitter.png"];
/* end of subclass-based cells block */
// Return the cell
return cell;
}
你从厦门国际银行文件到文件的所有者连接您的代理和datesource? – chetem 2014-09-12 15:10:35
我使用故事板。如何在storyborad中做到这一点? – 2014-09-12 15:15:31
点击您的收藏视图。然后在连接检查,点击并拖动从代理到文件的所有者和相同的数据源 – chetem 2014-09-12 15:16:47