0

試圖讓它如此,如果用戶向左滑動,應用程序將向後導航。最近我獲得的唯一成功是如果我指定UITableView;如果一個單元格已被選中,然後在單元格內發生滑動,它將向後導航,但就是這樣。我想這樣做,用戶可以在屏幕上的任何地方輕掃,而不必限制在表格單元格中刷入值。完成後,將顯示初始數組菜單。任何反饋?代碼如下:UIGestureRecognizer問題:試圖向後導航

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    arrayNo = [[NSMutableArray alloc] init]; 
    [[self myTableView] setDelegate:self]; 
    [[self myTableView] setDataSource:self]; 

    UISwipeGestureRecognizer * back = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(reLoad)]; 
    [back setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
    [self.view addGestureRecognizer:back]; 

    if (back) 
    { 
     NSLog(@"SWIPED"); 
     NSString *arts = @"Arts and Museums"; 
     NSString *coffee = @"Coffee and Bakeries"; 
     NSString *tours = @"Tours and Festivals"; 
     NSString *hotels = @"Hotels and Inns"; 
     NSString *leisure = @"Leisure and Recreation"; 
     NSString *music = @"Live Music"; 
     NSString *bars = @"Night Clubs and Bars"; 
     NSString *food = @"Restaurants"; 
     NSString *shopping = @"Shopping"; 
     NSString *transportation = @"Transportation"; 

     [arrayNo removeAllObjects]; 

     [arrayNo addObject:arts]; 
     [arrayNo addObject:coffee]; 
     [arrayNo addObject:tours]; 
     [arrayNo addObject:hotels]; 
     [arrayNo addObject:leisure]; 
     [arrayNo addObject:music]; 
     [arrayNo addObject:bars]; 
     [arrayNo addObject:food]; 
     [arrayNo addObject:shopping]; 
     [arrayNo addObject:transportation]; 
    } 
} 

回答

0

我相信我讓事情太複雜。爲了解決,我現在使用這個:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    UISwipeGestureRecognizer * back = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(backUp1)]; 
    [back setDirection:(UISwipeGestureRecognizerDirectionLeft)]; 
    [self.view addGestureRecognizer:back]; 

    if ([cell.textLabel.text isEqualToString: @"Arts and Museums"]) 
    {   
     NSString *galleries = @"Art Galleries"; 
     NSString *dramatic = @"Dramatic Arts"; 
     NSString *museums = @"Museums"; 

     [arrayNo removeAllObjects]; 

     [arrayNo addObject:galleries]; 
     [arrayNo addObject:dramatic]; 
     [arrayNo addObject:museums]; 

     [self.myTableView reloadData]; 
    } 
} 

-(void)backUp1 
{ 
    NSLog(@"SWIPED"); 
    NSString *arts = @"Arts and Museums"; 
    NSString *coffee = @"Coffee and Bakeries"; 
    NSString *tours = @"Tours and Festivals"; 
    NSString *hotels = @"Hotels and Inns"; 
    NSString *leisure = @"Leisure and Recreation"; 
    NSString *music = @"Live Music"; 
    NSString *bars = @"Night Clubs and Bars"; 
    NSString *food = @"Restaurants"; 
    NSString *shopping = @"Shopping"; 
    NSString *transportation = @"Transportation"; 

    [arrayNo removeAllObjects]; 

    [arrayNo addObject:arts]; 
    [arrayNo addObject:coffee]; 
    [arrayNo addObject:tours]; 
    [arrayNo addObject:hotels]; 
    [arrayNo addObject:leisure]; 
    [arrayNo addObject:music]; 
    [arrayNo addObject:bars]; 
    [arrayNo addObject:food]; 
    [arrayNo addObject:shopping]; 
    [arrayNo addObject:transportation]; 

    [self.myTableView reloadData]; 
}