IOS 开发小记 ————————collection view 总结
2015-12-25 20:37
211 查看
1 正常新建项目2 拖一个collection 到 controller 中3 修改其中默认的一个cellview 加入 imageview 和 label然后新建一个viewcontroller 和 cellview 对接 ,在storyboard 把ID 设为 对应的viewcontroller 的名字4 使用collection 的controller 需要 . h中 实现两个接口
#import <UIKit/UIKit.h>@interface Test1ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>@property (strong, nonatomic)NSMutableArray *dataMArr;@property (weak, nonatomic) IBOutlet UICollectionView *mkconllection;@end5 对应的实现 :- (void)viewDidLoad {[superviewDidLoad];[selfsetUpCollection];// Do any additional setup after loading the view.}-(void)setUpCollection{self.dataMArr = [NSMutableArrayarray];for(NSInteger index =0;index<9; index++){UIImage *image = [UIImageimageNamed:[NSStringstringWithFormat:@"%ld",(long)index+1]];NSString *title = [NSStringstringWithFormat:@"{0,%ld}",(long)index+1];NSDictionary *dic =@{@"image": image,@"title":title};[self.dataMArraddObject:dic];}self.mkconllection.delegate =self;self.mkconllection.dataSource =self;}#pragma mark - Collection View Data Source-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{returnself.dataMArr.count;}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{static NSString *collectionCellID =@"myCollectionCell";collectionCellmk *cell = (collectionCellmk *)[collectionViewdequeueReusableCellWithReuseIdentifier:collectionCellIDforIndexPath:indexPath];NSDictionary *dic =self.dataMArr[indexPath.row];UIImage *image = dic[@"image"];NSString *title = dic[@"title"];cell.CellImage.image = image;cell.celllabel.text = title;return cell;};注意事项1 cell 的 identifier 需要手动加入 myCollectionCell 而且需要和 实现函数中使用的 id 一致staticNSString *collectionCellID = @"myCollectionCell";collectionCellmk *cell = (collectionCellmk *)[collectionViewdequeueReusableCellWithReuseIdentifier:collectionCellIDforIndexPath:indexPath];2 如果崩溃无法找issue ui 有可能是 连接太多出的问题
相关文章推荐
- ios 编译第三方库
- iOS在分类中声明属性的方法(不提倡使用)以及关联对象介绍
- IOS省电
- iOS项目中获取验证码倒计时及闪烁问题解决方案
- 走上一条归路:IOS I am coming
- 原 IOS开发NSBundle对象使用详解
- iOS 两个tableview的 瀑布流
- iOS 开发中如何使用半透明模糊效果
- iOS MediaPlayer加载视频
- iOS 画虚线的两种方法
- iOS开发----Xcode7升级之后插件无法使用解决办法
- IOS NSLocking协议,NSLock,NSConditionLock,NSRecursiveLock,NSCondition
- iOS 随笔
- ios NSCharacterSet使用讲解
- iOS退出程序的代码
- iOS方法作为属性传递
- iOS显示GIF图片(3中方法)
- iOS开发封装一个可以响应超链接的label——基于RCLabel的交互扩展
- iOS可执行文件瘦身方法
- iOS把对象直接转化成NSDictionary或JSON