【问题标题】:UIGestureRecognizer Issue: trying to navigate backwardsUIGestureRecognizer 问题:尝试向后导航
【发布时间】:2013-05-03 01:23:34
【问题描述】:

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

【问题讨论】:

    标签: uitableview xcode4 uigesturerecognizer uiswipegesturerecognizer


    【解决方案1】:

    我确实认为我把事情弄得太复杂了。为了解决,我现在使用这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多