我第一次创建UIControlerView时,似乎从未激活过代理。请告诉我哪里出错了。
谢谢! 顺便说一句,我通过从故事板中拖出来创建IBOutlet ......
·H
#import <UIKit/UIKit.h>
@interface CollectionController : UIViewController<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UICollectionView *controllerTableView;
@end
的.m
#import "CollectionController.h"
#import "CollectionVIewCell.h"
@interface CollectionController ()
@end
@implementation CollectionController
- (void)viewDidLoad
{
[super viewDidLoad];
[[self controllerTableView]setDelegate:self];
[[self controllerTableView]setDataSource:self];
// Do any additional setup after loading the view.
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 10;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier=@"Cell";
CollectionVIewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.labelDisplay.text=@"hi";
//set up data in images
return cell;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:2)
尝试在xib中而不是在代码中连接UICollectionView
的委托和数据源。
答案 1 :(得分:1)
由于“弱”属性,您的controllerTableView是否可能被取消分配?尝试使用“强”,看看是否有帮助。
答案 2 :(得分:0)
我在这里推错了,应该是
CollectionController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"CollectionController"];
[self.navigationController pushViewController:controller animated:YES];
答案 3 :(得分:0)