ios - UIButton 以及 IBAction 和 segue 的顺序

标签 ios uibutton segue

假设我有一个 UIButton 控件,并且我将 @IBAction 方法附加到它的点击和 segue 上。是否保证在 segue 之前调用 click 方法?

提前致谢。

最佳答案

这样做,这将非常适合您的情况..

在您的第一个 ViewController.h 中创建一个属性来存储 indexPath

@property (nonatomic,strong) NSIndexPath *indexPath;

在你的第二个 ViewController.h 中创建一个属性来存储 indexPath

@property (nonatomic,strong) NSIndexPath *indexPath;

现在在你的第一个 ViewController.m 文件中

暂时忘掉 IBAction,在你的 cellForRow 中写这个选择器

[cell.btnOnCell addTarget:self action:@selector(btnAction:event:) forControlEvents:UIControlEventTouchUpInside];

写这个方法

-(IBAction)btnAction: (UIButton *)sender event:(id)event
{
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    CGPoint currentTouchPosition = [touch locationInView:self.tblView];
    self.indexPath = [self.tblView indexPathForRowAtPoint:currentTouchPosition];
    NSLog(@"%li",(long)self.indexPath.row);

   [self performSegueWithIdentifier:@"segueIdToYourSecondVC" sender:self];
}

不写这个方法(这个方法会在你的performSegueWithIdentifier之后调用)

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
 {
     if ([[segue identifier] isEqualToString:@"segueIdToYourSecondVC"])
     {
         // Get reference to the destination view controller
         YourSecondViewController *vc = [segue destinationViewController];
         vc.indexPath=self.indexPath;

     }
 }

谢谢..希望这对你有帮助。

关于ios - UIButton 以及 IBAction 和 segue 的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291427/

相关文章:

iphone - UIDeviceRGBColor 泄漏 - 如何修复?

iOS 无法更改 UIButton 的框架

swift - 为什么我的 UIButton 在 segue 之后仍然存在?

ios - 为什么我不能在 xcode 6.1 中使用 show segue?

iphone - 标签未显示在叠加 UIView 中

ios - 在新 iPad 上运行 iOS6 应用程序

ios - 返回 App 时 UIButton 动画停止?

ios - 导航栏在 push segue 循环中消失

swift - 从 TabeViewCell 中的 UIButton 触发 Segue

ios - 获取本地 PDF 页面高度 - iOS