假设我有一个UIButton
控件,并且在单击时附加了两个@IBAction
方法,并选择了它。是否保证click方法在segue之前被调用?
提前致谢。
最佳答案
这样做,这将非常适合您的情况。
在您的第一个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/