【发布时间】:2015-02-24 11:56:27
【问题描述】:
我在UIView 中有一个UITableView,我们称之为view_A。有一个UIViewController,叫它mainViewController。里面有一个UIButton。在点击该按钮时,我将 view_A 作为子视图添加到 mainViewController 的视图中。表格视图中有几个菜单项。问题是 tableview 没有正确响应触摸。我必须长按单元格才能进行选择。它没有添加任何手势。没有其他视图覆盖它。这绝对是奇怪的,这种行为。请查看以下代码并指出可能导致问题的原因。
这是 mainViewcontroller 中的委托实现/演示:
-(void) showDropDownMenu: (UIButton *) sender
{
UINib *nib = [UINib nibWithNibName:@"DropDownMenuView" bundle:nil];
self.myView = [[nib instantiateWithOwner:self options:nil] objectAtIndex:0];
self.myView.hidden = NO;
self.myView.tag = 101;
self.myView.delegate = self;
self.myView.btnBack.hidden = YES;
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.2;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromBottom ;
transition.delegate = self;
[self.myView.layer addAnimation:transition forKey:nil];
[self.view addSubview:self.myView];
}
-(void) hideDropDownMenu
{
CATransition *transition = nil;
transition = [CATransition animation];
transition.duration = 0.2;//kAnimationDuration
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromTop;
transition.delegate = self;
[self.myView.layer addAnimation:transition forKey:nil];
self.myView.tag = 102;
[UIView commitAnimations];
}
-(void) navigateBack
{
}
-(void) themeSelected: (NSIndexPath *) indexPath
{
NSLog(@"%ld",(long)indexPath.item);
themeNumber = [NSString stringWithFormat:@"%li",(indexPath.row+1)];
[self setUpTheme];
}
这是 cell.h 文件的实现:
@interface ThemeTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UILabel *themeName;
@property (weak, nonatomic) IBOutlet UIImageView *themePreview;
这是 cell.m 文件的实现:
#import "ThemeTableViewCell.h"
@implementation ThemeTableViewCell
- (void)awakeFromNib {
// Initialization code
//ORIGINAL 82
self.clipsToBounds = YES;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
更新:我记录了手势,结果以某种方式将长按手势设置为单元格。
【问题讨论】:
-
您的表格单元包含任何出现此问题的操作系统的附件视图(如复选框、详细信息披露按钮等)。在我的一个项目中,我在 IOS7.0 中遇到了同样的问题,我在 UItableviewcell 中使用了附件视图。为了解决这个问题,我删除了这个视图。
-
不,这是一个普通的表格视图。单元格中只有 imageview。
标签: ios objective-c iphone uitableview uiview