2013-03-15 78 views

回答

0

雅。你可以創建編程

-(void)loadView 
{ 
[super loadView]; 

UICollectionViewFlowLayout *layout= [[UICollectionViewFlowLayout alloc]init]; 
self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout]; 
self.collectionView.delegate=self; 
self.collectionView.dataSource=self; 
[self.collectionView setAutoresizingMask:UIViewAutoresizingFlexibleHeight |UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin]; 

[self.collectionView setBackgroundColor:[UIColor clearColor]]; 
[self.collectionView registerClass:[UICollectionViewCell class] 
    forCellWithReuseIdentifier:@"Cell"]; 


[self.view addSubView:self.collectionView]; 
} 
0

你必須創建一個實現UICollectionViewDataSource和UICollectionViewDelegate這樣的UIViewController子類:

@interface MyViewController:UIViewController<UICollectionViewDelegate, UICollectionViewDataSource> 
@end 

然後在.M文件你實現所需的UICollectionViewDataSourceUICollectionViewDelegate方法

並覆蓋 - [UIViewController viewDidLoad]像這樣:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    UICollectionView *collectionView = [UICollectionView alloc] initWithFrame:self.view.bounds]; 
    collectionView.delegate = self; 
    collectionView.dataSource = self; 
    [self.view addSubview:collectionView]; 
} 
+0

查看更多此處http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UICollectionView_class/Reference/Reference.html – 2013-03-15 05:15:46

相關問題