如何刷手势segue回到以前的视图ios?

时间:2014-01-08 05:17:56

标签: ios segue uiswipegesturerecognizer

我正试图将我来自的视图转回(QueryController)。 但是没有滑动动作...... 不确定我遗失了什么。

enter image description here

@implementation ProfileController4


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

        UISwipeGestureRecognizer * Swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
        Swiperight.direction=UISwipeGestureRecognizerDirectionRight;
        [self.view addGestureRecognizer:Swiperight];

        UISwipeGestureRecognizer * Swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
        Swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
        [self.view addGestureRecognizer:Swipeleft];
    }
    return self;
}



-(void)swipeleft:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //Do what you want here

}

-(void)swiperight:(UISwipeGestureRecognizer*)gestureRecognizer
{
    //Do what you want here

    [self performSegueWithIdentifier: @"friendsBackToQuerySeg" sender: self];

//      [[UIViewController alloc] initWithNibName:@"QueryController1" bundle:nil];

}

1 个答案:

答案 0 :(得分:4)

UISwipeGestureRecognizer方法中添加viewDidLoad代码。

- (void)viewDidLoad
{
    [super viewDidLoad];

    UISwipeGestureRecognizer * Swiperight=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swiperight:)];
    Swiperight.direction=UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:Swiperight];

    UISwipeGestureRecognizer * Swipeleft=[[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeleft:)];
    Swipeleft.direction=UISwipeGestureRecognizerDirectionLeft;
    [self.view addGestureRecognizer:Swipeleft];
}