【发布时间】:2026-01-23 22:15:01
【问题描述】:
我的应用程序从名为TaskController : UINavigationController 的根控制器开始
作为UINavigationController 的根视图控制器,我创建了类TaskRootController : UIViewController<UITableViewDelegate>(它已添加为视图UITableView);
当我启动应用程序时,我只看到任务根控制器的标题和背景颜色。
但我没有看到表格视图。
如果我的应用程序以TaskRootController 作为rootViewController 开头,我会看到表格视图。
在可能的情况下如何查看表格视图?
编辑
@implementation TaskRootController
@synthesize taskRootView; //table view
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"SIZE x:%f,y:%f ; %f:%f", self.view.bounds.origin.x, self.view.bounds.origin.y, self.view.bounds.size.width, self.view.bounds.size.height);
self.view.backgroundColor = [UIColor grayColor];
self.title = @"Root";
self.taskRootView = [[UITableView alloc] initWithFrame: self.view.bounds style:UITableViewStylePlain];
[self.view addSubview:self.taskRootView];
self.taskRootView.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat result = 20.0f;
if([tableView isEqual:self.taskRootView])
{
result = 40.0f;
}
return result;
}
@end
【问题讨论】:
-
发布你的代码。你是如何设置 rootViewController 的?
-
@PratyushaTerli:回来+1!!!
-
如果您已将表格视图放置在 .xib 中。然后确保将表视图委托和数据源添加到文件所有者。
-
粘贴您编写的代码 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions mehtod
-
@user1863111-检查我的编辑:0
标签: iphone ios objective-c cocoa-touch uiview