1
我有一个UICollectionView
它有2个部分。每个部分标题都有一个按钮。我试图将部分ID发送到prepareForSegue
上的另一个视图控制器,如下所示。如何识别哪个按钮点击哪个部分UICollectionView iOS?
if ([[segue identifier] isEqualToString:@"ManualCapture"]){
NSIndexPath *indexPath = [self.collectionView indexPathForCell:sender];
ManualCapture *vc = [segue destinationViewController];
vc.sectionId = indexPath.section;
}
但它发送0
作为部分ID。有没有任何可能的方式来获得部分ID?如何根据按钮点击发送sectionId。基本上我想这样做,当我点击第1部分中的按钮,在prepareForSegue
上它应该被发送0,如果我点击了第2节中的按钮,在prepareForSegue
上它应该被发送1.我该怎么做?
在此先感谢!在集合视图的委托方法
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSString *tagStr = [NSString stringWithFormat:@"%d%d",indexPath.section,indexPath.row];
yourButton.tag = [tagStr intValue];
}
然后当你要检查哪个部分或指数是获得它通过它的标签,就像这样:
'sender'确实是单元格还是实际上是按钮?它需要是'indexPathForCell:'的单元格才能工作。 – rmaddy 2015-02-10 05:25:51
实际上是一个按钮。那我该怎么做? – codebot 2015-02-10 05:27:58
如果你将一个非正确的单元格传递给'indexPathForCell:',那么得到的'indexPath'将会是'nil',这就是为什么你得到0的部分。 – rmaddy 2015-02-10 05:29:28