Objective c 导航到按钮上的视图控制器从collectionview单元格中单击
我有一个由集合视图组成的viewcontroller。此集合视图有一个UIbutton块。我想在单击此按钮时导航到另一个视图控制器并传递一些数据。请注意,它是一个UIButton块Objective c 导航到按钮上的视图控制器从collectionview单元格中单击,objective-c,uiviewcontroller,uibutton,uicollectionviewcell,Objective C,Uiviewcontroller,Uibutton,Uicollectionviewcell,我有一个由集合视图组成的viewcontroller。此集合视图有一个UIbutton块。我想在单击此按钮时导航到另一个视图控制器并传递一些数据。请注意,它是一个UIButton块 非常感谢您的帮助 首先,确保包含集合视图的viewcontroller中嵌入了NavigationController 其次,有两种方法可以将某些数据传递给另一个视图控制器: 第一种方式: 让我们设置按钮选择器 [button addTarget:select action:@selector(buttonTouch
非常感谢您的帮助 首先,确保包含集合视图的viewcontroller中嵌入了NavigationController 其次,有两种方法可以将某些数据传递给另一个视图控制器:
[button addTarget:select action:@selector(buttonTouched:)
forControlEvents:UIControlEventTouchUpInside];
然后让我们实现选择器,如下所示
- (void)buttonTouched:(id)sender {
// Find tableViewCell
UIView *view = field;
while (view && ![view isKindOfClass:[UICollectionViewCell class]]){
view = view.superview;
}
UICollectionViewCell *cell = (UICollectionViewCell *)view;
NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
// TODO: get data for above indexPath
UIViewController *nextViewControler = [[UIViewController alloc] init];
[self.navigationController pushViewController:nextViewControler animated:YES];
}
@property(复制,非原子)dispatch\u block\u t button touchedblock代码>
然后让我们在cellForItemAtIndexPath
方法中实现它
__弱类型(自我)弱自我=自我;
cell.buttonTouchedBlock=^{
[weakSelf buttonotuchedat:indexPath];
}