Iphone 在选项卡栏控制器中嵌入了导航控制器,但模拟没有显示任何内容
我对iOS开发非常陌生,如果这里的专家能够帮助我解决我的问题,我将不胜感激。目前,我的应用程序非常基本,没有什么作用。在尝试向现有视图添加选项卡栏之前,一切正常。我不确定我遗漏了什么,但在运行模拟时没有显示任何内容。我会尽力解释我的应用程序的结构,以便你们更好地理解这个问题 应用程序中当前存在以下内容Iphone 在选项卡栏控制器中嵌入了导航控制器,但模拟没有显示任何内容,iphone,objective-c,ios,Iphone,Objective C,Ios,我对iOS开发非常陌生,如果这里的专家能够帮助我解决我的问题,我将不胜感激。目前,我的应用程序非常基本,没有什么作用。在尝试向现有视图添加选项卡栏之前,一切正常。我不确定我遗漏了什么,但在运行模拟时没有显示任何内容。我会尽力解释我的应用程序的结构,以便你们更好地理解这个问题 应用程序中当前存在以下内容 FeedList:嵌入UINavigationController中的UITableViewController FeedCell:为FeedList创建的UITableViewCell Feed
//AppDelegate.h
#import <UIKit/UIKit.h>
#import "FeedList.h"
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
FeedList *feedList;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) FeedList *feedList;
@property (nonatomic, retain) UITabBarController *tabBarController;
- (void)customizeAppearance;
@end
//AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window, feedList, tabBarController;
// Entry point
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
tabBarController = [[UITabBarController alloc] init];
feedList = [[FeedList alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:feedList];
tabBarController.viewControllers = [NSArray arrayWithObject:nav];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
//AppDelegate.h
#进口
#导入“FeedList.h”
@接口AppDelegate:NSObject
{
UIWindow*窗口;
FeedList*FeedList;
UITabBarController*tabBarController;
}
@属性(非原子,保留)IBUIWindow*window;
@属性(非原子,保留)FeedList*FeedList;
@属性(非原子,保留)UITabBarController*tabBarController;
-(无效)定制外观;
@结束
//AppDelegate.m
#导入“AppDelegate.h”
@实现AppDelegate
@综合窗口、feedList、Tabbar控制器;
//入口点
-(无效)应用程序IDFinishLaunching:(UIApplication*)应用程序
{
tabBarController=[[UITabBarController alloc]init];
feedList=[[feedList alloc]init];
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:feedList];
tabBarController.viewControllers=[NSArray arrayWithObject:nav];
[窗口添加子视图:tabBarController.view];
[WindowMakeKeyandVisible];
}
更新(问题已解决)
我意识到在添加行
tabBarController.viewControllers=[NSArray arraywhithobject:nav]之后代码>事情开始失控。检查完Apple的文档后,原因是如果此属性的值在运行时发生更改,则选项卡栏控制器会在安装新的视图控制器之前删除所有旧的视图控制器。因此,我们需要将新的选项卡栏控制器设置为根视图控制器 我同意达斯汀的评论,如果你要开始新的生活,你应该使用故事板。我认为您的方法有什么错误,或者与典型方法不同的是,您没有将tabBarController添加为子视图,而是将self.window的rootViewController设置为:
// Entry point
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
tabBarController = [[UITabBarController alloc] init];
feedList = [[FeedList alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:feedList];
tabBarController.viewControllers = [NSArray arrayWithObject:nav];
//******* This is my correction *******
window.rootViewController = tabBarController;
//******* *******
[window makeKeyAndVisible];
}
当然,无法从您提供的信息判断tableview是否设置正确,因此不能保证它会显示您的表格。如果您是新手,您应该使用故事板,而不是尝试以编程方式创建所有内容。