ios - IOS 中的索引路径嵌套 Tableview

标签 ios objective-c uitableview

我有一个 tableview,它位于 tableview 单元格内。我需要该子 TableView “cellForRowAtIndexPath”方法中的主 TableView 索引路径。我坚持这一点。我的数据源和委托(delegate)方法在同一个类中。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Configure the cell...
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil && [tableView tag] == 200) {
    //main tableview
 }
else if(cell == nil && tableView.tag == 106)
{
  //sub tableview
   here I need the index path of main tableview
} 

}

如何获取主 TableView 的索引路径? enter image description here

最佳答案

试试这个:

UITableViewCell *cell = (UITableViewCell *) tableView.superview.superview.superview;
UITableView *curTableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [curTableView indexPathForCell:cell];

关于ios - IOS 中的索引路径嵌套 Tableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17439999/

相关文章:

ios - 无法将类型 '[String]' 的值分配给类型 'String?'

ios - Metal :iPhone 5/iOS 8 上为 "Failed creating a default system device!"

ios - 为什么执行insertRows后,tableview numberOfRowsInSection不更新?

ios - 非常奇怪的崩溃,可能与 ARC 有关并且只出现在 iPhone 5s 上

objective-c - 在不同版本的 OSX 上调试 XCode 之外的应用程序(查看异常、日志等)

iphone - 制作多 View 应用程序的有效方法?

objective-c - 多个复选标记来自

php - 如何在另一个 Controller 上快速显示服务器在应用程序中获取的数据

ios - 如何在Swift 4的UITableView中制作多个级别的节

ios - canDisplayBannerAds 是否仅使用 iAd 横幅的单个实例?