如果您的應用程序在iOS 3.2或更高版本上,您可以使用UISwipeGestureRecognizer進行如下操作。
//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];
而在你的控制器的某個地方;
-(void)handleSwipeFrom {
if (swipeLeftRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
// Your code here to go back to the main view
}
}
這隻會對正確的滑動作出反應,並會讓你的錶行爲正常。希望這可以幫助! :)