我想問一個關於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'?非常感謝你。
感謝您的回覆。我嘗試將代碼放在SimpelTableView.h中,但收到很多錯誤。我應該在哪裏放置代碼? – Questions 2010-07-21 01:16:34
第一塊代碼替換了你在switchPageShowTable中的代碼(我認爲它是MyViewController的方法)。請注意,我的版本釋放模態視圖控制器,以便您不必在別處跟蹤它。 「self.title」部分是SimpleTableView的職責,可能會進入init ...或viewDidLoad。順便說一下,SimpleTableView的名稱有點混亂,我將其命名爲SimpleTableViewController類。 – Costique 2010-07-21 04:58:56