4

これはローカライズされた問題です。私はたくさんのコードを投稿し、多くの説明をします。うまくいけば...誰かがこれで私を助けることができます。スワイプジェスチャが呼び出された後にtableView:didSelectRowAtIndexPathが起動しない

私のアプリケーションでは、「Facebookスタイル」のメニューがあります。より具体的には、iOS Facebookアプリ。このメニューには2通りの方法でアクセスできます。メニューボタンを押すか、スワイプしてメニューを開きます。ボタンを使用してメニューを開閉するとき、tableView:didSelectRowAtIndexPathメソッドはセルに触れると完全に起動します。スワイプメソッドを使用してメニューを開いたり閉じたりすると、それはできません。あなたは発砲するためにテーブルのセルに2回触れなければなりません。これらのメソッドのコードは、いくつかのクラスではまったく同じですが、これは私が問題を抱えている唯一のクラスです。見てみましょう。

#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 
+0

私はタップが垂直スワイプの後に決して発射されないことを除いて同じ問題があります。 –

答えて

-1

は、インデックスパスを計算し、スワイプがで行われたセルを決定し、あなたのgestureRecognizerコードからdidSelectRowAtIndexPathを呼び出す:私はどこかにボールを落としてるかどうかを確認します。

+0

スワイプはビュー上で行われます。セルではありません。スワイプは2つのことを行います。メニューを開いて閉じます。それでおしまい。 – tallybear

+0

説明から、あなたの問題は、スワイプがdidSelectRowAtIndexPathを呼び出さないということです。正しい場合は、スワイプの下にあるセルを特定してスワイプアクションコードから自分自身を呼び出すことができます。 –

+1

ここには...私はスワイプがdidSelectRowAtIndexPathを呼び出さないようにしています。スワイプは、tableViewで行われているアクションとは関係ありません。スワイプはサイドメニューを開き、閉じます。問題は...ユーザーがメニューを閉じるためにスワイプすると、didSelectRowAtIndexPathメソッドはtableView上のセルに初めて触れるときに起動しません。あなたはそれを2度触れなければなりません。私はtable.userInteractionEnabled = YESを持っています。スワイプメソッドでメニューを閉じます。 – tallybear

関連する問題