草庐IT

iphone - TableView :didSelectRowAtIndexPath not firing after swipe gesture is called

coder 2023-09-30 原文

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

在我的应用程序中,我有一个“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

最佳答案

确定滑动发生在哪个单元格中,计算索引路径,并从您的 gestureRecognizer 代码中调用 didSelectRowAtIndexPath。

关于iphone - TableView :didSelectRowAtIndexPath not firing after swipe gesture is called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9588671/

有关iphone - TableView :didSelectRowAtIndexPath not firing after swipe gesture is called的更多相关文章

  1. iphone - 扩展 restful_authentication/AuthLogic 以支持匿名 iPhone 的延迟登录的最佳方法是什么? - 2

    我正在构建一个与RubyonRails后端对话的iPhone应用程序。RubyonRails应用程序还将为Web用户提供服务。restful_authentication插件是提供快速和可定制的用户身份验证的绝佳方式。但是,我希望iPhone应用程序的用户在新列中存储一个由手机的唯一标识符([[UIDevicedevice]uniqueIdentifier])自动创建的帐户。稍后,当用户准备好创建用户名/密码时,帐户将更新为包含用户名和密码,iPhone唯一标识符保持不变。用户在设置用户名/密码之前不能访问该网站。然而,他们可以使用iPhone应用程序,因为该应用程序可以使用它的标识符

  2. iphone - 设计和 Rails 3 中的 http 身份验证 - 2

    我有一个使用deviseonrails3的应用程序。我想启用http身份验证,以便我可以从iPhone应用程序向我的网络应用程序进行身份验证。如何从我的iPhone应用程序进行身份验证以进行设计?这安全吗?还是我应该进行不同的身份验证? 最佳答案 从设计的角度来看,您有3个选择:1)使用基本的http身份验证:您的iPhone应用程序有一个secretkey-这是在您的iPhone应用程序代码中烘焙的-用于对网络应用程序的每个请求进行身份验证。Google搜索:“设计基本的http身份验证”2)您可以通过在您的iPhone应用程序中

  3. iphone - 在没有 Mac 的情况下开发 iPhone 应用程序? - 2

    这个问题在这里已经有了答案:关闭13年前。PossibleDuplicates:HowcanIdevelopforiPhoneusingaWindowsdevelopmentmachine?我想为我妻子的手机构建一个iPhone应用程序,但我对购买Mac作为一次性工作的开发平台不感兴趣。应用程序:应该在iPhone上独立运行(即没有网络连接)完全可以接受使用iPhoneJavascript库之一创建的GUI会做一些数据库IO来读取和更新数据没有商业值(value),永远不会被任何人使用这是我的想法:越狱iPhone在iPhone上安装Ruby+Sinatra使用Sinatra编写应用程

  4. iphone - iPhone 原生应用的测试驱动设计 - 2

    我正在试验iPhoneSDK并在Nic博士的rbiPhoneTest项目中做一些TDD。我想知道有多少人(如果有的话)成功地使用了这个或任何其他iPhone/Cocoa测试框架?更重要的是,我想知道如何最好地断言专有的二进制请求/响应协议(protocol)。这个想法是通过网络发送二进制请求并接收二进制响应。请求和响应是使用byteand'ing和or'ing创建的。我正在使用黄金副本模式来测试我的请求。这是我到目前为止所拥有的。不要笑,因为我是ObjectiveC和Ruby的新手:requireFile.dirname(__FILE__)+'/test_helper'require'

  5. iphone - 如何从视频中提取方向信息? - 2

    在网络上浏览了大量文档后,iPhone似乎总是以480x360的纵横比拍摄视频,并在视频rails上应用变换矩阵。(480x360可能会改变,但对于给定设备而言始终相同)这是一种在iOS项目中修改ffmpeg源代码并访问矩阵http://www.seqoy.com/correct-orientation-for-iphone-recorded-movies-with-ffmpeg/的方法这是在iOS-4中查找转换矩阵的更清晰的方法Howtodetect(iPhoneSDK)ifavideofilewasrecordedinportraitorientation,orlandscape.

  6. javascript - 是否允许将javascript代码下载到iPhone - 2

    我有一个混合应用程序,它基本上是一个从UIWebview内的应用程序文件夹运行的网站。问题是我打算通过从互联网下载整个网站然后替换旧网站来更新我的网站。今天发现苹果现在提供了AppStoreReviewGuidelines等规则:2.7Appsthatdownloadcodeinanywayorformwillberejected2.8Appsthatinstallorlaunchotherexecutablecodewillberejected因为我的网站有html、css和javascript,这是否意味着我的应用程序将被拒绝或有机会被接受?你对此有何看法?

  7. javascript - 拖动以像在 iPhone 中一样使用 jQuery 更改图像幻灯片 - 2

    我正在为我的站点使用超大型jquery插件。它带有下一张和上一张幻灯片的按钮。我想在其中实现拖动更改功能。如果有人点击并将鼠标向右移动,它应该充当下一张幻灯片按钮。但是我如何使用jquery来实现呢?我怎么知道用户何时单击n向左/向右拖动http://buildinternet.com/project/supersized/ 最佳答案 jQuery将mouseUp、mouseDown和mouseMove识别为事件。您必须在mouseDown上捕获鼠标位置,在它移动时更新位置并将其与您最初捕获的位置进行比较。虽然这是高度理论化的,但请

  8. javascript - iPhone 为 (hash and 3) 和 (Asterisk and 8) 返回相同的按键事件 - 2

    我正在处理电话验证,需要使用电话号码自动格式化输入,并且只允许添加数字字符。但是,当我尝试使用keydown和keypress限制输入时,iPhone允许我输入#和*。当我检查keydown值时,它们分别与3和8相同(键码51和56)。这在Android浏览器中完美运行,但在iPhone中失败。任何人都遇到过类似的问题。$(formSelector+'input[name^="phone"]').on('keydownkeypress',function(e){//Allow:backspace,delete,tab,escape,andenterif(e.keyCode==46||e

  9. javascript - iPhone 应用程序和移动 safari 之间是否有任何共享状态? - 2

    我有一个网站和一个本地iPhone应用程序。该应用程序注册了一个自定义协议(protocol)。我希望网站在适当的时候自动重定向到协议(protocol),但前提是用户安装了应用程序(以避免烦人的对话框)。这意味着我需要从应用程序中写入一些我可以在移动safari中读取的状态,以将应用程序标记为已安装。Cookie似乎不存在跨进程。还有其他地方可以存放我的标记吗? 最佳答案 看this博客文章,了解Apple如何为MobileMeGallery应用程序做到这一点。它涉及应用程序在Safari中打开一个网站(在您的服务器上),该网站将

  10. javascript - 如何连接到 iPhone 的 webkit 调试器? - 2

    新的iOS6功能是,您可以在桌面safari中调试在设备或模拟器上运行的html和javascript。我想,这个功能是基于WebkitRemoteDebuggingProtocol.如何在没有桌面Safari的情况下连接到在iPhone上运行的webkit?我可以使用websockets为在Android上运行的移动Chrome执行此操作,但如何为iOS设备执行此操作? 最佳答案 ios-webkit-debug-proxy项目(来自Google!)就是这样做的。 关于javascri

随机推荐