【问题标题】:Push new view on clicking Table Cell, How's that possible ? [closed]在单击表格单元格时推送新视图,这怎么可能? [关闭]
【发布时间】:2012-03-14 07:47:17
【问题描述】:

当用户在tableview上选择一个单元格时,我想推送一个新视图,这怎么可能?

我想在新视图上打印选定的单元格数据?给我编码

【问题讨论】:

    标签: iphone objective-c ios uitableview uiview


    【解决方案1】:

    重写 UItableViewDelegate 的这个委托方法。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    //Value Selected by user
          NSString *selectedValue = [displayValues objectAtIndex:indexPath.row];
    //Initialize new viewController
          NewViewController *viewController = [[NewViewController alloc] initWithNibName:@"NewViewController" bundle:nil];
    //Pass selected value to a property declared in NewViewController
          viewController.valueToPrint = selectedValue;
    //Push new view to navigationController stack
          [self.navigationController pushViewController:viewController animated:YES];
    }
    

    查看此链接了解更多信息
    1) Table view tutorial
    2)StackOverflow similar question

    【讨论】:

      【解决方案2】:

      您可以使用UINavigationController 并在didSelectRowAtIndePath: 方法中调用pushViewController:

      为了显示信息,我将创建一个新的UIViewController,并创建一些您可以设置用于显示信息的属性。

      【讨论】:

        【解决方案3】:

        您必须在方法“(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath”中实现代码。当您选择表格中的单元格时,将调用此方法。这就是为什么你必须实现你想要的。

        希望下面的代码对你有所帮助。

         - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        
        
        
                            if (!yourObject) {
                            yourObject = [[yourViewController alloc] initWithNibName:@"yourViewController" bundle:nil];
        
                        }
        
                        UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
                        self.navigationItem.backBarButtonItem = backBarButtonItem;
                        [backBarButtonItem release];
                        [self.navigationController pushViewController:yourObject animated:YES];
        
            }
        

        【讨论】:

          【解决方案4】:

          didSelectRowAtIndexPath 方法中尝试这个,你可以创建类的对象,你可以 用户:NavigationControllerpresentModleViewController 去另一个视图。

          [self.navigationController pushViewController:yourClassobject animated:YES];
          

          [self presentModalViewController:yourClassobject animated:YES];
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2012-07-20
            • 2016-07-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-11-28
            • 2015-07-13
            相关资源
            最近更新 更多