Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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
Iphone 当连接到选项卡栏控制器时,TableView不会切换到详细视图_Iphone_Uiviewcontroller_Pushviewcontroller - Fatal编程技术网

Iphone 当连接到选项卡栏控制器时,TableView不会切换到详细视图

Iphone 当连接到选项卡栏控制器时,TableView不会切换到详细视图,iphone,uiviewcontroller,pushviewcontroller,Iphone,Uiviewcontroller,Pushviewcontroller,我创建了一个选项卡栏应用程序,删除了默认的FirstView和SecondView,并添加了以下两个ViewController: JustAnotherView(它只是一个内部带有UIView的UIViewController) MyListFitems(内部带有TableView的UIViewController) 我有一个叫做ListOfItemsDetailViewController的第三个ViewController,里面有一个UIView,当用户触摸其中一个TableView单元格

我创建了一个选项卡栏应用程序,删除了默认的FirstView和SecondView,并添加了以下两个ViewController:

  • JustAnotherView(它只是一个内部带有UIView的UIViewController)
  • MyListFitems(内部带有TableView的UIViewController)
  • 我有一个叫做ListOfItemsDetailViewController的第三个ViewController,里面有一个UIView,当用户触摸其中一个TableView单元格时应该调用它

    应用程序编译时没有问题。我可以触摸两个选项卡栏按钮并显示正确的视图

    问题: 单击TableView单元格时,将执行切换到详细视图的代码(不会发生崩溃或错误),但该视图永远不会显示

    下面是应用程序和调试器的屏幕截图,其中包含一个NSLog,显示它通过了pushViewController而没有崩溃:

    这是代码

    MyListOfItemsViewController.h

    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "ListOfItemsDetailViewController.h";
    
    @interface MyListOfItemsViewController : UIViewController {
        ListOfItemsDetailViewController *listOfItemsDetailViewController;
    }
    
    @property (nonatomic, retain) ListOfItemsDetailViewController *listOfItemsDetailViewController;
    
    
    @end
    
    请帮忙。非常感谢

    我一直在疯狂地尝试在iOS平台上实现基本导航

    另外,请原谅外行的问题,我知道你们中的大多数人已经了解如何做到这一点

    提前谢谢。
    Jaosn

    表视图中:didSelectRowAtIndexPath:
    您正在通过
    self.navigationController
    引用导航控制器,该导航控制器可能不存在。您必须在选项卡视图中将UINavigationController用作一个视图控制器,并且该导航控制器的rootViewController应为MyListFitEmsViewController


    请注意,您需要一个UINavigationController,以使您的详细信息视图能够推送和自我导航。navigationController只是一种检索以前创建并插入到层次结构中的UINavigationController的方法。

    而不是将第二个选项卡的viewcontroller设置为tableviewcontroller,将其设置为UINavigationController,并将navcontroller的RootViewController设置为“MyListFitems”。完成此操作后,您将可以访问viewcontroller中的navigationController属性,并可以使用推送和弹出


    或者,如果您不想这样做,剩下的唯一方法就是以编程方式在视图之间设置动画(即删除一个视图并添加另一个视图,或在当前视图的顶部添加另一个视图)

    非常感谢。这正是我想要的。当我了解到这一点时,iOS开发中的许多事情变得更加清晰。非常感谢您的回复。这正是我想要的。非常清楚。我对中的第一个给出了正确的回答,因为他们似乎都指向了同一个方向(当你回想起来时,我错过了非常重要的导航控制器-duh)。这确实是帮助我理解发生了什么的链接:
    #import "MyListOfItemsViewController.h"
    @implementation MyListOfItemsViewController
    @synthesize listOfItemsDetailViewController;
    
    #pragma mark -
    #pragma mark View lifecycle
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = self.editButtonItem;
        self.title = @"My List Of Items";
        NSLog(@"My List Of Items Did Load");
    }
    
    #pragma mark -
    #pragma mark Table view data source
    // Customize the number of sections in the table view.
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
        return 5;
    }
    
    
    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        static NSString *CellIdentifier = @"Cell";
        NSString *cellMessage;
    
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    
        cellMessage = [NSString stringWithFormat:@"indexPath: %d",indexPath.row];       
        cell.textLabel.text = cellMessage;
        return cell;
    }
    
    #pragma mark -
    #pragma mark Table view delegate
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        ListOfItemsDetailViewController *vcListOfItemsDetail = [[ListOfItemsDetailViewController alloc] 
                                        initWithNibName:@"ListOfItemsDetail" bundle:[NSBundle mainBundle]];
        self.listOfItemsDetailViewController = vcListOfItemsDetail;
        [vcListOfItemsDetail release];
        [self.navigationController pushViewController:self.listOfItemsDetailViewController animated:YES];
    
        NSLog(@"Did Execute didSelectRowAtIndexPath WITHOUT Crashing or Error.");
    
    }
    
    #pragma mark -
    #pragma mark Memory management
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Relinquish ownership any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
        // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
        // For example: self.myOutlet = nil;
        NSLog(@"My List Of Items View Did Unload");
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    
    
    @end