Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone tableView:didSelectRowAtIndexPath在调用滑动手势后未触发_Iphone_Objective C_Ios_Uitableview_Uiswipegesturerecognizer - Fatal编程技术网

Iphone tableView:didSelectRowAtIndexPath在调用滑动手势后未触发

Iphone tableView:didSelectRowAtIndexPath在调用滑动手势后未触发,iphone,objective-c,ios,uitableview,uiswipegesturerecognizer,Iphone,Objective C,Ios,Uitableview,Uiswipegesturerecognizer,这是一个局部问题。我将发布大量代码,并提供大量解释。有希望地。。。有人可以帮我 在我的应用程序中,我有一个“Facebook风格”菜单。更具体地说,iOS Facebook应用程序。您可以通过两种不同的方式访问此菜单。您可以触摸菜单按钮,也可以滑动以打开菜单。当使用按钮打开和关闭菜单时,tableView:didSelectRowAtIndexPath方法会在触摸单元格时完美触发。当使用滑动方法打开和关闭菜单时。。。事实并非如此。您必须触摸表格单元格两次,才能触发该方法。这些方法的代码在几个类中

这是一个局部问题。我将发布大量代码,并提供大量解释。有希望地。。。有人可以帮我

在我的应用程序中,我有一个“Facebook风格”菜单。更具体地说,iOS Facebook应用程序。您可以通过两种不同的方式访问此菜单。您可以触摸菜单按钮,也可以滑动以打开菜单。当使用按钮打开和关闭菜单时,
tableView:didSelectRowAtIndexPath
方法会在触摸单元格时完美触发。当使用滑动方法打开和关闭菜单时。。。事实并非如此。您必须触摸表格单元格两次,才能触发该方法。这些方法的代码在几个类中完全相同,但是,这是我唯一有问题的一个。看一看,;看看我是不是把球丢在什么地方了:

#import "BrowseViewController.h"



@implementation BrowseViewController

@synthesize browseView, table, countriesArray, btnSideHome, btnSideBrowse, btnSideFave, btnSideNew, btnSideCall, btnSideBeset, btnSideEmail, btnSideCancelled, menuOpen, navBarTitle, mainSearchBar, tap;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.font = [UIFont fontWithName:@"STHeitiSC-Medium" size:20.0];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:1.0];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.text = @"Countries";
self.navBarTitle.titleView = label;
[label sizeToFit];

CheckNetworkStatus *networkCheck = [[CheckNetworkStatus alloc] init];
BOOL internetActive = [networkCheck checkNetwork];

if (internetActive) {

    tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
    [self.view addGestureRecognizer:tap];
    tap.delegate = self;
    tap.cancelsTouchesInView = NO;

    UISwipeGestureRecognizer *oneFingerSwipeLeft = 
    [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)];
    [oneFingerSwipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
    [[self view] addGestureRecognizer:oneFingerSwipeLeft];

    UISwipeGestureRecognizer *oneFingerSwipeRight = 
    [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
    [oneFingerSwipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
    [[self view] addGestureRecognizer:oneFingerSwipeRight];

    menuOpen = NO;
    table.userInteractionEnabled = YES;
    NSArray *countries = [[NSArray alloc] initWithObjects:@"United States", @"Canada", @"Mexico", nil];
    self.countriesArray = countries;
} else {
    //No interwebz, notify user and send them to the home page
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Connection Error" message:@"Failed to connect to the server. Please verify that you have an active internet connection and try again. If the problem persists, please call us at **********" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [message show];
    PassportAmericaViewController *homeView = [[PassportAmericaViewController alloc]
                                               initWithNibName:@"PassportAmericaViewController" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:homeView animated:YES];
}

[super viewDidLoad];
}


-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection: (NSInteger)section
{
  return [countriesArray count];
  NSLog(@"Number of objecits in countriesArray: %i", [countriesArray count]);
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"CellIdentifier";

  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell == nil) {
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
      cell.textLabel.textColor = [UIColor whiteColor];
      cell.textLabel.font = [UIFont fontWithName:@"STHeitiSC-Medium" size:20.0];
  }


  NSUInteger row = [indexPath row];

  cell.textLabel.text = [countriesArray objectAtIndex:row];

  return cell;
}

- (void)tableView:(UITableView *)table
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSString *countrySelected = [countriesArray objectAtIndex:indexPath.row];
Campground *_Campground = [[Campground alloc] init];
_Campground.country = countrySelected;

StateViewController *stateView = [[StateViewController alloc]
                                    initWithNibName:@"StateView" bundle:[NSBundle mainBundle]];
stateView._Campground = _Campground;

[self.navigationController pushViewController:stateView animated:YES];

}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

-(void) dismissKeyboard {

[mainSearchBar resignFirstResponder];

}

-(IBAction)goBack:(id)sender{

[self.navigationController popViewControllerAnimated:YES];

}

-(void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
if ([animationID isEqualToString:@"slideMenu"]){
    UIView *sq = (__bridge UIView *) context;
    [sq removeFromSuperview];

}
}

- (IBAction)menuTapped {
NSLog(@"Menu tapped");
CGRect frame = self.browseView.frame;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
[UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.browseView)];

if(!menuOpen) {
    frame.origin.x = -212;
    menuOpen = YES;
    table.userInteractionEnabled = NO;
}
else
{
    frame.origin.x = 0;
    menuOpen = NO;
    table.userInteractionEnabled = YES;
}

self.browseView.frame = frame;
[UIView commitAnimations];
}

-(IBAction) sideHome:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
PassportAmericaViewController *homeView = [[PassportAmericaViewController alloc]
                                           initWithNibName:@"PassportAmericaViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:homeView animated:YES];
table.userInteractionEnabled = YES;

}
-(IBAction) sideBrowse:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
BrowseViewController *browseView2 = [[BrowseViewController alloc]
                                    initWithNibName:@"BrowseView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:browseView2 animated:YES];
table.userInteractionEnabled = YES;

}
-(IBAction) sideBeset:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
BesetCampgroundMapViewController *besetMapView = [[BesetCampgroundMapViewController alloc]
                                                  initWithNibName:@"BesetCampgroundMapView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:besetMapView animated:YES];
table.userInteractionEnabled = YES;

}
-(IBAction) sideFave:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
FavoritesViewController *faveView = [[FavoritesViewController alloc] initWithNibName:@"FavoritesView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:faveView animated:YES];
table.userInteractionEnabled = YES;


}
-(IBAction) sideNew:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
NewCampgroundsViewController *theNewCampView = [[NewCampgroundsViewController alloc]
                                                initWithNibName:@"NewCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:theNewCampView animated:YES];
table.userInteractionEnabled = YES;

}
-(IBAction) sideCancelled:(id)sender{

CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;
menuOpen = NO;
CancelledCampgroundsViewController *cancCampView = [[CancelledCampgroundsViewController alloc]
                                                    initWithNibName:@"CancelledCampgroundsView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:cancCampView animated:YES];
table.userInteractionEnabled = YES;

}
-(IBAction) sideCall:(id)sender{

NSLog(@"Calling Passport America...");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:**********"]];
table.userInteractionEnabled = YES;

}
-(IBAction) sideEmail:(id)sender{

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"mailto:***************"]];
table.userInteractionEnabled = YES;

}

-(void) searchBarSearchButtonClicked: (UISearchBar *)searchBar {
SearchViewController *search = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:[NSBundle mainBundle]];
NSString *searchText = [[NSString alloc] initWithString:mainSearchBar.text];
search.searchText = searchText;
[self dismissKeyboard];
[self.navigationController pushViewController:search animated:YES];
table.userInteractionEnabled = YES;
menuOpen = NO;
CGRect frame = self.browseView.frame;
frame.origin.x = 0;
self.browseView.frame = frame;

}

-(void) swipeLeft:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
    CGRect frame = self.browseView.frame;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
    [UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.browseView)];
    frame.origin.x = -212;
    menuOpen = YES;
    self.browseView.frame = frame;
    table.userInteractionEnabled = NO;
    [UIView commitAnimations];

} else {
    //menu already open, do nothing
}
}

-(void) swipeRight:(UISwipeGestureRecognizer *)recognizer {
if (!menuOpen) {
    //menu closed, do nothing
} else {
    CGRect frame = self.browseView.frame;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector( animationDidStop:finished:context: )];
    [UIView beginAnimations:@"slideMenu" context:(__bridge void *)(self.browseView)];
    frame.origin.x = 0;
    menuOpen = NO;
    self.browseView.frame = frame;
    table.userInteractionEnabled = YES;
    [UIView commitAnimations];

}
}

- (void) viewWillDisappear:(BOOL)animated {
[self.table deselectRowAtIndexPath:[self.table indexPathForSelectedRow] animated:animated];
[super viewWillDisappear:animated];
}


- (void)didReceiveMemoryWarning {
NSLog(@"Memory Warning!");
[super didReceiveMemoryWarning];

// Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
self.table = nil;
self.countriesArray = nil;
self.browseView = nil;

[super viewDidUnload];

}

@end

确定滑动发生在哪个单元格中,计算索引路径,然后从您的手势识别器代码调用didSelectRowAtIndexPath。

滑动发生在视图上。不是牢房。刷卡可以做两件事。打开并关闭菜单。就是这样。根据您的描述,您的问题似乎是刷卡没有调用DidSelectRowatineXpath。如果这是正确的,那么您可以通过确定哪个单元格在刷卡下,从刷卡操作代码中自己调用它。。。我不希望刷卡调用DidSelectRowatineXpath。滑动与在tableView上发生的任何操作无关。滑动只会打开和关闭侧菜单。问题是。。。一旦用户滑动关闭菜单,第一次触摸tableView上的单元格时,DidSelectRowatineXpath方法不会触发。你得摸它两次。我有table.userInteractionEnabled=YES;在滑动方法中关闭菜单。我也有同样的问题,除了我,垂直滑动后不会触发点击