嘿,我目前正在使用iPhone SDK,並且在通過3個視圖傳遞NSString時遇到問題如何通過3個ViewControllers傳遞一個NSString?
我能夠在2個視圖控制器之間傳遞NSString,但我無法將其傳遞給另一個視圖控制器。我的代碼如下...
`- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)index`Path {
NSString *string1 = nil;
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"items"];
string1 = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
ViewController2 *vc2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:[NSBundle mainBundle]];
vc2.string1 = string1;
[self.navigationController pushViewController:vc2 animated:YES];
[vc2 release];
vc2 = nil;
}
在「視圖控制器2」實現
我通過執行以下操作....
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = string1;
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"icon_time.png"]
style:UIBarButtonItemStylePlain
//style:UIBarButtonItemStyleBordered
target:self
action:@selector(goToThirdView)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
}
但我在標題欄可以使用「字符串1」也有一個NavBar按鈕在右側,我想推新視圖
- (void)goToThirdView
{
ViewController3 *vc3 = [[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:NESW animated:YES];
vc3.string1 = string1 ;
[vc3 release];
vc3 = nil;
}
如何將同一字符串傳遞到第三個視圖? (或第四個)