在我的应用程序中,我有六个按钮需要放在 pcollectionview 上。我已经在应用程序中放置了pscollectionview,但我不能使用数据源和委托方法?任何人都可以提出这个例子会有帮助吗?以下是我的代码:
- (void)viewDidLoad
{
self.collectionView = [[PSCollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
self.collectionView.delegate = self;
self.collectionView.collectionViewDelegate = self;
self.collectionView.collectionViewDataSource = self;
self.collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.collectionView];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn1.frame = CGRectMake(10, 30, 140, 130);
[self.collectionView addSubview:btn1];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn2.frame = CGRectMake(170, 30, 140, 130);
[self.collectionView addSubview:btn2];
UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn3.frame = CGRectMake(10, 180, 140, 130);
[self.collectionView addSubview:btn3];
UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn4.frame = CGRectMake(170, 180, 140, 130);
[self.collectionView addSubview:btn4];
UILabel *loadingLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 100, 50, 20)];
loadingLabel.text = @"Loading...";
loadingLabel.textAlignment = UITextAlignmentCenter;
[self.collectionView addSubview:loadingLabel];
//self.collectionView.loadingView = loadingLabel;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (NSInteger)numberOfViewsInCollectionView:(PSCollectionView *)collectionView {
return 1;
}
- (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView viewAtIndex:(NSInteger)index {
}
- (CGFloat)heightForViewAtIndex:(NSInteger)index {
NSDictionary *item = [self.items objectAtIndex:index];
return [NDACCustomView heightForViewWithObject:item inColumnWidth:self.collectionView.colWidth];
}
- (void)collectionView:(PSCollectionView *)collectionView didSelectView:(PSCollectionViewCell *)view atIndex:(NSInteger)index {
// NSDictionary *item = [self.items objectAtIndex:index];
// You can do something when the user taps on a collectionViewCell here
}