开发者

cannot display the navigation title in the table on iPhone application

I want to ask a question about the iPhone application. I write a program which will display a table. However, I don't know why I cannot display the navigation title in the table. The following is my code

// code

- (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);

}

The table can only display the item but not the title. Can any one help me?

// ---------- Update 1 --------------

The code in the [self flowControl] will call two functions, both of the function is to add the items, e.g [displayNameArray addObject:@"John Chan"];

// ---------- Update 2 --------------- In my program, the are 2 view controllers.

1) MyViewController

2) SimpleTableView

The first one is used to let the user to enter the information, the second one is used to display the content in table format.

My project name is USERPROJE开发者_开发问答CT

//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 

And it is one of the content within the 'MyViewController.m', I use this to switch to the control from the 'MyViewController.m' to 'SimpleTableView.m'

- (void) switchPageShowTable {

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

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

}

Is it affect the use of the 'self' in the calling title? Thank you very much.


The title you expect to see is displayed in a navigation bar, which is usually part of UINavigationController. To make it work you have to do the following:

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

And (a small nitpick) instead of

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

you can do this:

self.title = @"Table Title Hello";

unless you have a reason to explicitly use the navigationItem.


Is the view your trying to load a subclass of UITableViewController?

And what does [self flowControl] do exactly?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜