2010-07-20 83 views
0

我想问一个关于iPhone应用程序的问题。我写了一个会显示一个表的程序。但是,我不知道为什么我无法在表格中显示导航标题。下面是我的代码无法在iPhone应用程序的表格中显示导航标题

//代码

- (void)viewDidLoad { 

    [super viewDidLoad]; 

    // control flow, call another user define function and add the items to the table 
    [self flowControl]; 

    //Set the title  
    self.navigationItem.title = @"Table Title Hello"; 

    // can see 
    // NSLog(@"self.navigationItem.title: %@", self.navigationItem.title); 

} 

表只能显示项,但不是标题。谁能帮我?

// ----------更新1 --------------

在[自流量控制]的代码将调用两个功能,这两者的功能是添加项目,例如[displayNameArray addObject:@"John Chan"];

// ---------- Update 2 --------------- 在我的程序中,是2个视图控制器。

1)MyViewController

2)SimpleTableView

第一个是用来让用户输入的信息,第二个是用于显示在表格式的内容。

我的项目名称是USERPROJECT

//The following is the content of the .m 
#import "MyViewController.h" 
#import "USERPROJECT.h" 
#import "SimpleTableView.h" 

@implementation USERPROJECT 

@synthesize window; 
@synthesize myViewController; 


- (void)applicationDidFinishLaunching:(UIApplication *)application {  

    MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; 
    [self setMyViewController:aViewController]; 
    [aViewController release]; 

    UIView *controllersView = [myViewController view]; 
    [window addSubview:controllersView]; 

    // Override point for customization after application launch 
    [window makeKeyAndVisible]; 
} 


- (void)dealloc { 
    [myViewController release]; 
    [window release]; 
    [super dealloc]; 
} 

@end 

而且它是“MyViewController.m”,我用它来从“MyViewController.m”切换到控制“SimpleTableView中的内容之一。 m'

- (void) switchPageShowTable { 

    NSLog(@"%d: switchPageShowTable", order); 
    order++; 

    SimpleTableView *simpleTableView = [[SimpleTableView alloc] initWithNibName:nil bundle:nil]; 
    [self presentModalViewController:simpleTableView animated:YES]; 

} 

它是否会影响在调用标题中使用'self'?非常感谢你。

回答

2

您期望看到的标题显示在导航栏中,该导航栏通常是UINavigationController的一部分。为了使它工作,你必须做到以下几点:

SimpleTableView *simpleTableView = [[SimpleTableView alloc] initWithNibName:nil bundle:nil]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController: simpleTableView]; 
[self presentModalViewController:navController animated:YES]; 
[simpleTableView release]; 
[navController release]; 

而不是

self.navigationItem.title = @"Table Title Hello"; 

(小鸡蛋里挑骨头),你可以这样做:除非你有充分的理由

self.title = @"Table Title Hello"; 

明确使用navigationItem。

+0

感谢您的回复。我尝试将代码放在SimpelTableView.h中,但收到很多错误。我应该在哪里放置代码? – Questions 2010-07-21 01:16:34

+0

第一块代码替换了你在switchPageShowTable中的代码(我认为它是MyViewController的方法)。请注意,我的版本释放模态视图控制器,以便您不必在别处跟踪它。 “self.title”部分是SimpleTableView的职责,可能会进入init ...或viewDidLoad。顺便说一下,SimpleTableView的名称有点混乱,我将其命名为SimpleTableViewController类。 – Costique 2010-07-21 04:58:56

0

是您试图加载UITableViewController的子类的视图?

那么[self flowControl]究竟做了什么?

+0

感谢您的回复。我已经在上面编辑了这篇文章,你会看看。此外,你是什么意思“是你试图加载UITableViewController的子类的视图?”。我是目标C的绿色,你想介意给我解释一下吗? – Questions 2010-07-20 03:26:03

+0

界面看起来像这样吗? @interface ViewController:UITableViewController {} @end – 2010-07-20 03:31:11

+0

感谢您的回复,并且我更新了上面的帖子,您是否介意查看。我在上面添加了我的项目结构。此外,界面代码就像你输入的内容。谢谢。 – Questions 2010-07-20 03:49:42

相关问题