Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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 未调用自定义单元格didSelectRowAtIndexPath_Ios_Objective C_Xcode - Fatal编程技术网

Ios 未调用自定义单元格didSelectRowAtIndexPath

Ios 未调用自定义单元格didSelectRowAtIndexPath,ios,objective-c,xcode,Ios,Objective C,Xcode,我创建了一个通用的master-detail应用程序。我在自定义类(MasterViewController类)中有一个表视图。这是一个UITableViewController类。 使用故事板,我在iPhone表格视图中创建了一个自定义单元格。自定义单元格包含3个标签和1个图像。 在情节提要中,此表视图数据源和委托设置为MasterViewController类。 我的自定义表视图单元格在属性检查器的视图部分中启用了“用户交互”。 在我的MasterViewController类中,UITab

我创建了一个通用的master-detail应用程序。我在自定义类(MasterViewController类)中有一个表视图。这是一个UITableViewController类。 使用故事板,我在iPhone表格视图中创建了一个自定义单元格。自定义单元格包含3个标签和1个图像。 在情节提要中,此表视图数据源和委托设置为MasterViewController类。 我的自定义表视图单元格在属性检查器的视图部分中启用了“用户交互”。 在我的MasterViewController类中,UITableViewDataSource方法(如“numberOfSectionsInTableView”)工作正常。 我在表视图和详细视图之间定义了一个序列。 当我运行应用程序并在表视图中选择单元格时,不会为iPhone调用didSelectRowAtIndexPath。我的prepareForSegue方法执行,并出现segue

我已经读了很多关于DidSelectRowatineXpath的帖子,但是我没有解决我的问题

如有任何提示,将不胜感激

我的自定义单元格标识符是ConversationCell。segue标识符为ShowConversationDetails。 我在numberOfRowsInSection的第一行使用断点进行调试,但从未输入此方法

segue工作,细节视图显示带有“Hello”文本的我的标签

一些代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];

//NSLog(@"Rows %lu",(unsigned long)[sectionInfo numberOfObjects]);
return [sectionInfo numberOfObjects];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"ConversationCell";

UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

[self configureCell:cell atIndexPath:indexPath];

return cell;

}

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

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {


   [[self.fetchedResultsController sections] count]);


   NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
    self.detailViewController.detailItem = object;
}
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowConversationDetails"]) {

    NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];

    Event *e = nil;

    e = [self.fetchedResultsController objectAtIndexPath:selectedIndex];

    UIViewController *destinationViewController = [segue destinationViewController];
    [segue.destinationViewController setLabel:@"Hello"];
    }
}
selectedIndex为空,就好像在执行prepareForSeque时不再选择行一样

顺便说一句,为了安全起见,我从模拟器中删除了应用程序,然后对项目进行了清理,没有任何更改


Tim

除了您已经提到的检查之外,这里还有一些您可能需要考虑的其他检查:

检查方法是否与此完全相同(字母大小写无差异):

检查控制器是否实现了
UITableViewDelegate
协议

检查交互是否有效(更改选择样式选项,以便单元格在触摸事件时更改颜色)

检查内部是否没有作为第一响应者的任何视图,并删除交互(删除要测试的单元格中的任何视图)


尝试以编程方式允许对表进行选择
[tableView SetAllowSelection:YES]

您确定您的
UITableViewDelegate
对象被正确设置为表视图的
委托吗?(这与将其设置为数据源是分开的。)

我最终删除了我的MasterViewController和DetailViewController。我重新创建了它们,现在一切正常。不知道我第一次做错了什么。感谢所有提供建议的人。
蒂姆

谢谢你的反馈。MasterViewController设置为dataSource和Delegate。我怀疑您的单元格-“ConversationCell”有一个位于顶部的视图,不允许触摸通过它传递到表视图单元格。如果您进入cellforRow、HeightForRowAtIndex等方法,并且您说您在DidSelectRowAtIndex路径上遇到问题,那么这必须是由于最上面的视图,它不允许触摸通过单元格。您所能做的就是,只需将“SetUserInterActionEnabled:NO”设置为表视图单元格中的视图,然后点击行进行测试。不要关闭单元格的交互。干杯。:)雷诺,谢谢你的提示。我忽略了提到,我取消了为自定义单元格的每个元素选择“启用用户交互”。自定义单元格的交互保持打开状态。不幸的是,完成所有这些操作后,没有调用DidSelectRowAtIndexPath。请删除所有视图或设置隐藏:对单元格的xib文件上的所有视图都为TRUE,然后尝试构建,以查看是否能够获得触摸?谢谢Eric。我的didSelectRowAtIndexPath与您注意到的完全相同。我检查了DidHighlightRowatineXpath是否会在选中我的单元格时被调用,但它也没有被选中。看起来,虽然我将MasterViewController设置为委托,但没有调用任何UITableViewDelegate方法。然后尝试在viewDidLoad中以编程方式设置委托,只是为了安全起见(tableView.delegate=self;)谢谢Eric。我之前试过了,但也存在同样的问题。我添加了一些代码,我在prepareForSegue中尝试了这些代码,但发现我无法确定所选行。这就好像行在到达prepareForSeque时不再被选中一样。我需要在选择时确定行内容,以便将适当的值传递到详细信息页面。
@interface MasterViewController : UITableViewController     <NSFetchedResultsControllerDelegate,ASIHTTPRequestDelegate,UITableViewDelegate, UITableViewDataSource>
{
NSMutableArray *eventsArray;

}
NSIndexPath *selectedIndex = [self.tableView indexPathForSelectedRow];
    NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:selectedIndex];
    NSString *messageTableID = [[object valueForKey:@"messagetableid"] description];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath