2012-08-01 58 views

回答

0

假設你有食品名稱,諸如數組:

NSArray *foodArr = [NSArray arrayWithObjects:@"Chicken",@"Cheese",@"Hamburger"] 

和想要的標題爲「奶酪」(即在索引1對象),則需要從內部得到的NSString數組:

NSString *foodTitle = [foodArr objectAtIndex:1]; 

那麼您可以將標題設置爲字符串:

self.navigationController.title = foodTitle; 
+0

你也可以說,'UIViewController'必須是一個'UINavigationController'內包裹着。歡呼:) – 2012-08-01 11:00:41

+0

真的,謝謝:) – Stavash 2012-08-01 11:01:22

0

你可以做到這一點,如果你甲肝Ë字符串數組的更多信息:

yourViewController.title = [self.myNameArray objectAtIndex:selectedIndex]; 

,如果你有對象了title屬性的數組:

yourViewController.title = [[self.myObjectArray objectAtIndex:selectedIndex] title]; 
0

如果您使用的UINavigationController與導航欄你可以很容易就遵循:

-(void) viewDidLoad { 

    self.navigationItem.title = [NSString stringWithString:@"%@",[yourTitles objectAtIndex:yourIndex]; 

} 

如果你不使用它,那麼你將手動添加UILabel,它會顯示你的標題,並做同樣的事情:

-(void) viewDidLoad { 

    [titleLabel setText:[NSString stringWithString:@"%@",[yourTitles objectAtIndex:yourIndex]]; 

} 
0

是非常簡單的

//Assuming you are displaying food item in tableView 
//vController is class object which is going to be pushed on navigation stack 
//Put this line in didSelectRowAtIndexPath method 

yourViewControllerObject.title = [foodItemArray objectAtIndex:indexPath.row]; 
相關問題