Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Ios 未调用UITableView didSelectRowAtIndexPath_Ios_Objective C_Uitableview_Selection - Fatal编程技术网

Ios 未调用UITableView didSelectRowAtIndexPath

Ios 未调用UITableView didSelectRowAtIndexPath,ios,objective-c,uitableview,selection,Ios,Objective C,Uitableview,Selection,我在采用UITableViewDelegate和UITableViewDataSource协议的UIViewController内部有一个UITableView行数部分和单元格行数索引路径已实现 故事板中有数据源和委托的出口。为TableView选择单个选项。选中触摸时显示选择 我在模拟器上运行project,触摸表格单元格,得到了didHighlightRowatineXpath调用,但是didSelectRowatineXpath或willSelectRowatineXpath从未被调用 我

我在采用
UITableViewDelegate
UITableViewDataSource
协议的
UIViewController
内部有一个
UITableView
<代码>行数部分和
单元格行数索引路径
已实现

故事板中有数据源和委托的出口。为TableView选择单个选项。选中触摸时显示选择

我在模拟器上运行project,触摸表格单元格,得到了
didHighlightRowatineXpath
调用,但是
didSelectRowatineXpath
willSelectRowatineXpath
从未被调用

我忘了什么?什么会以这种方式影响TableView

另外,我知道,有很多这样的问题,但我花了几个小时在谷歌上搜索和阅读stackoverflow,仍然没有解决我的问题

TestViewController.h:

@interface TestViewController:ViewController

@end

TestViewController.m:

@interface TestViewController ()
@property (strong) IBOutlet UITableView *tableView;
@end

@implementation TestViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"selected");
}

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"highlighted");
}

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"FilterCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.textLabel.text = @"some text";
    return cell;
}

@end

如果看不到代码,很难说,但请尝试以下方法:

1)
didselectrowatinedexpath
来自
UITableViewDelegate
不是数据源,是否连接了它

2) 仔细检查
didSelectRowAtIndexPath
的签名。从某个受信任的源复制粘贴它。可能是打错了

3) 确保插座连接正确。使用调试器将其停在某个地方,比如说
viewDidLoad
并打印dataSource&delegate(
po self.tableView.dataSource
debugger命令),确保它们指向正确的对象

4) 行是否以可视方式被选中?也许您在代码或情节提要中将
cell.userInteractionEnabled
设置为NO

5) 表视图在序列图像板中有一个选择属性:(可以吗?)

6)也许您的表格处于编辑模式?从调试中记录以查看。


7) 是否从
indexPathsForSelectedRows
方法的角度选择行?如果您覆盖并记录对单元格的
所选访问器的调用会怎么样?

我知道了。问题出在project使用的库中


我的ViewController是从库的ViewController实现继承的,它捕获了所有的手势

1)是,两者都已连接(委托和数据源)。调用DidHighlightRowatineXpath。2) 从ios文档复制(以防万一)。3) 记录了两个连接,它们是OK的,我可以看到视觉效果和单元格突出显示的日志;cell的userInteractionEnabled被选中,我不会在代码中更改它;设置了tableview的单选。6)在didHighlight tableview中。编辑为否;甚至改为“编辑模式下的单一选择”也没有帮助。7) 我也在didHighlight中检查它,它总是空的哇,我通过长时间点击它得到了一个选定的单元格(非常长而且非常不自然),现在我不能选择任何其他单元格。我还注意到,在故事板或代码中将单元格的选择样式更改为蓝色(从灰色)并不能真正改变它。问题出在那里使用的库中,但仍然非常感谢您的帮助!您不认为添加代码会有帮助吗?或者你希望我们有读心术吗?@vikingosegundo我会加上,但没有什么特别的。我甚至把我的课程改成了一个简单的课程testing@SerhiiYakovenko,它的ViewController继承自STableViewController(用于“加载更多”实现)。坏名字,我知道。请进一步解释以帮助他人,然后选择这是答案。每次我都会这样做,请检查您的手势识别器,如果您将手势识别器添加到表视图,didSelectRowAtIndexPath将不会运行。这也让我不止一次@EdwardAnthony。我设法通过不取消视图中的触摸来解决它<代码>UITapGestureRecognitzer*tapRec=[[UITapGestureRecognitzer alloc]initWithTarget:自我操作:@selector(点击:)];[tapRec setCancelsTouchesInView:NO]森林,你是个该死的天才!