开发者

How to push/pop controller by swipe in iPhone SDK?

Currently i am developing an iPhone application in which navigation between two controls by swipe gesture recognizer.

Applicaiton structure is like this

How to push/pop controller by swipe in iPhone SDK?

For this i first load calendar screen and on it's view did load, i load home screen by using PushViewController. On home screen if user swipe's his left then calendar screen shows using PopViewController or if user swipe's his right then listview screen shows by PushViewController. This is working fine.

Now problem is that on my listview screen i am using a UITableViewController where Gesture Recognizer will not working perfectly, some time it cannot s开发者_如何学Cwipe.

How can i swipe between these screen perfectly, I want to swipe same as scrollview scrolling.

Please provide me some solution.


Provided your app is on iOS 3.2 or above, you can do this with a UISwipeGestureRecognizer as follows.

//Add Table
    UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(0, 20, 320, 460)];
    table.dataSource=self;
    table.delegate=self;
    [table reloadData];
    [self.view addSubview:table];
    [table release];

    //Add Gesture Recognizer
    swipeLeftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)];
    [table addGestureRecognizer:swipeLeftRecognizer];
    [swipeLeftRecognizer release];

And somewhere in your controller;

-(void)handleSwipeFrom {

    if (swipeLeftRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {

        // Your code here to go back to the main view

    }

}

This will react only for a right swipe and will let your table behave the normal way. Hope this helps! :)


After a long googling i found a solution. I am taking a scrollview with width of 3 screens and add calendar xib view on it's first screen frame, add home xib view on it's second screen frame and then add list xib view on it's third screen frame, with this i create a UINavigationController *navigationHome; id parentController; on home screen for managing home screen navigation from scrollview and make same technique for rest of the controllers this will work me fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜