【问题标题】:Objective-c PushView for a cell of TableView in an other TableViewObjective-c PushView 用于另一个 TableView 中的 TableView 单元格
【发布时间】:2015-07-16 01:47:41
【问题描述】:

我在显示选定单元格的详细信息时遇到了问题。但是这个单元格是在一个TableView 水平的,而这个TableView 是在另一个TableViewController 的一个单元格中。我希望你能理解我。

这里是 TableViewController(命名为 HostingTableViewController)的代码:

     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"CellWithTableInside";
        CellWithTableInside *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[CellWithTableInside alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
        cell.backgroundColor = [UIColor blackColor];

        NSArray *tabSection = [dictionarySection  keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2){
            return [obj1 compare:obj2];
        }];
        NSArray* sortedNumbers = [tabSection sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
            if ([obj1 integerValue] > [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedDescending;
            }

            if ([obj1 integerValue] < [obj2 integerValue]) {
                return (NSComparisonResult)NSOrderedAscending;
            }
            return (NSComparisonResult)NSOrderedSame;
        }];

        id key,value;

            key = [sortedNumbers objectAtIndex: [indexPath section]];
            value = [dictionarySection objectForKey: key];

[cell setCellData:[dictionaryClip objectForKey:key]];

        return cell;
    }

这里是用于显示细节控制器的 Cell 代码:

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

    DetailClip *secondVC = [[DetailClip alloc]initWithClip:[array objectAtIndex:[indexPath row]]];
    [pushVC.navigationController pushViewController:secondVC animated:YES];


}

pushVC 在这里初始化:

pushVC = [[HostingTableViewController alloc]init];

如果您需要更多信息或代码,请告诉我。

提前致谢:)

【问题讨论】:

    标签: ios objective-c uitableview detailsview horizontallist


    【解决方案1】:

    如果您对在单元格点击时添加代码感到困惑,您可以比较表格并通过比较其类型(表格名称)来添加操作

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if(tableView==NameOfYourFirstTable)//first table view cell tap
    {
        //write the code for your action
        DetailClip *secondVC = [[DetailClip alloc]initWithClip:[array objectAtIndex:[indexPath row]]];
        [pushVC.navigationController pushViewController:secondVC animated:YES];
    }
    else
    {
        //actions on click of other table view cell 
    }
    
    }
    

    【讨论】:

    • 谢谢,等我拿回我的电脑再测试一下,我的硬盘停止工作了:/
    猜你喜欢
    • 1970-01-01
    • 2018-12-21
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-01
    • 1970-01-01
    • 2014-03-21
    相关资源
    最近更新 更多