0

试图做到这一点,如果用户向左滑动,应用程序将向后导航。最近我唯一的成功是如果我指定了 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];
    }
}
4

1 回答 1

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];
}
于 2013-05-03T01:48:36.943 回答