UIGestureRecognizer问题:尝试向后导航

时间:2013-05-03 01:23:35

标签: uitableview xcode4 uigesturerecognizer uiswipegesturerecognizer

如果用户向左滑动,尝试这样做,应用程序将向后导航。最近我获得的唯一成功是如果我指定了UITableView;如果已经选择了一个单元格,然后在单元格内进行滑动,它将向后导航,但就是这样。我想这样做,以便用户可以在屏幕上的任何位置滑动,而不必仅限于在表格单元格中滑动值。完成后,将显示初始阵列菜单。任何反馈?代码如下:

- (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];
    }
}

1 个答案:

答案 0 :(得分: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];
}