所以我一直在研究名为 Readium
的 ePub 框架,他们最近为 IOS 创建了一个 SDK。
SDK 是一个完整的工作项目,它允许用户从 tableView
列表中选择一个 ePub,在选择一个之后,您会得到关于该 ePub 的元数据,之后您必须选择页面列表或书脊项目,在选择其中一页后,它最终会转到 ePub。
我想通过在 collectionView
中打开 ePub 列表并在选择 ePub 后直接转到该 ePub 的首页/封面来简化此过程。
我想知道的是,是否可以使用 tableView
的 viewController
和 data sources 来创建一个新的 Collection View
?我已经调整了这个项目以允许滑动导航。
最佳答案
可以很快完成。
1) 您必须告诉 Controller 您想要调整 Collection View ,因此您的 .h
文件中有两个选项:
a) 如果您当前从 UITableView 继承 - 从 UICollectionViewController 继承 ViewController:
@interface YouViewControllerName : UICollectionViewController
b) 如果您继承自 UIViewController,只需设置您的 Controller 符合 CollectionView 委托(delegate)和数据源方法像这样
@interface YouViewControllerName : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource> { ... }
2) 然后你需要替换 TableView 委托(delegate)和数据源方法 用 Collection View 数据源和委托(delegate)方法,所以你需要替换这样的东西:
旧的:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath { ... }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { ... }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { ... }
新:
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath { ... }
- (NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section { ... }
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { ... }
因此,之前的委托(delegate)/数据源方法中的内容可以保持不变,因为不需要更改逻辑。
您可能需要实现一些更具体的方法,并进行一些设计正确的项目单元格大小等工作,但这是很自然的,因为您的布局被 Collection View 取代。
关于ios - 从现有的 tableView 数据源和 Controller 创建一个 collectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39844518/