views:

34

answers:

2

Hi, everyone,

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

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.

A: 

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

And what does [self flowControl] do exactly?

Conceited Code
@Conceited Code, thank you for your reply. I have edited the post in the above, would you take a look. Besides, what do you mean of "Is the view your trying to load a subclass of UITableViewController?". I am a green of the objective C, would you mind to explain to me?
Questions
Does the interface look something like this?@interface ViewController : UITableViewController {}@end
Conceited Code
@Conceited Code, thank you fro your reply, and I have updated the post above, would you mind to take a look. I add my project structure in the above. Besides, the interface code is like what you type. Thank you.
Questions
+1  A: 

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.

Costique
@Costique, thank you for your reply. I try to put the code in the SimpelTableView.h, but it receive lots of error. Where should I put the code?
Questions
The first block of code replaces the code you have in switchPageShowTable (I assume it is MyViewController's method). Note that my version releases the modal view controller so that you don't have to track it elsewhere. The "self.title" part is SimpleTableView's responsibility and may go into either init... or viewDidLoad. By the way, SimpleTableView is named a bit confusingly, I would name the class SimpleTableViewController.
Costique