我正在尝试从我的第一页上的按钮加载PatientListTableViewController,但没有成功。我有一个标签栏项目已经到达此页面。但是我希望从我的起始页面上的按钮访问同一页面,因为PatientListTableViewController是用户首次打开页面时在选项卡栏上看不到的选项卡项目。我该如何编码呢?
PatientListTableViewController的头文件包括:
@interface PatientListTableViewController : UITableViewController <PatientAddDelegate, NSFetchedResultsControllerDelegate, UINavigationBarDelegate, UITabBarControllerDelegate>{
提前感谢您提供任何帮助
PatientListTableViewController的头文件包括:
@interface PatientListTableViewController : UITableViewController [PatientAddDelegate, NSFetchedResultsControllerDelegate, UINavigationBarDelegate, UITabBarControllerDelegate] {
答案 0 :(得分:0)
如果您已将此视图控制器设置为UITabBarController的子视图控制器,我将在UITabBarController上使用setSelectedIndex:
或setSelectedViewController
。如果你不这样做,你就会遇到问题,因为你可能已经在两个不同的位置加载了视图控制器的视图(在标签栏下,以及手动加载它时放置它的任何地方)。
这是一些示例代码。我假设您的应用程序委托有一个实例变量myTabBarController
,并且您在UITabBarController中放置了两个视图控制器:myFirstViewController
和mySecondViewController
。我假设您已将这两个视图控制器设置为NIB文件中标签栏控制器的子项。
- (void)buttonPressed:(id)sender {
[myTabBarController setSelectedViewController:mySecondViewController];
// Alternately, you could set the index rather than the actual VC:
// [myTabBarController setSelectedIndex:1]
}
如果您的问题与加载没有NIB文件的视图控制器有关,请确保在该视图控制器的loadView
方法中正确设置视图层次结构。
答案 1 :(得分:0)
在将此代码实现到myFirstViewController后,上面的解决方案对我不起作用:
@implementation MyFirstViewController
@synthesize tabBarController;
在我的MyAppDelegate.h文件中,我有:
IBOutlet UITabBarController * tabBarController; IBOutlet MyTableViewController * patientListController; ....结束
在我的MyAppDelegate.m文件中,我有:
@implementation MyAppDelegate @synthesize patientListController;
@synthesize tabBarController; ......结束
我在这里错过了什么吗?