【发布时间】:2015-04-23 12:44:11
【问题描述】:
我正在开发一个自定义布局 collectionView,它具有被子外观,每个部分都有一个页脚。两个按钮在页脚内,每个按钮都有一个到另一个视图的 segue(我使用 IB 设置了 segues)。
页脚有自己的 indexPath,它在 UICollectionViewFlowLayout 类中分配(我在其中制作了自定义布局)。 footer 的 indexPath 是这样的 - {section - row} {0-0} {1-0} {2-0}....
我想保留这个 indexPath 信息,以便在链接到两个按钮的另一个视图中使用。
我尝试了“convertPoint: toView: ... indexPathForRowAtPoint”的方式,但没有奏效。我认为这是因为按钮不属于collectionViewItem,而是属于Footer。
在这种情况下,将每个 footerView 的 indexPath 传递给 segue 的最佳方式是什么?
任何带有代码示例的解决方案都将不胜感激。
// CollectionView DataSource
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
Footer *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
withReuseIdentifier:@"Footer"
forIndexPath:indexPath];
// set button images and labels
[footerview setButton];
// debug code : show current section number
footerview.footerLabel.text = [NSString stringWithFormat:@"Section %li", (long)indexPath.section];
return footerview;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"SeeAllPictures"]) {
// how to pass indextPath?
}
else if([[segue identifier] isEqualToString:@"GoDiary"]) {
// how to pass indextPath?
}
}
下面是Footer类的头部
#import <UIKit/UIKit.h>
@interface Footer : UICollectionReusableView
@property (strong, nonatomic) IBOutlet UILabel *footerLabel;
@property (strong, nonatomic) IBOutlet UIButton *seeAllPictures;
@property (strong, nonatomic) IBOutlet UIButton *goDiary;
@property (strong, nonatomic) IBOutlet UIImageView *seeAllPicturesImage;
@property (strong, nonatomic) IBOutlet UILabel *seeAllPicturesLabel;
@property (strong, nonatomic) IBOutlet UIImageView *goDiaryImage;
@property (strong, nonatomic) IBOutlet UILabel *goDiaryLabel;
- (void)setButton;
@end
【问题讨论】:
标签: ios objective-c iphone nsindexpath