В моем понимании вашего проекта:
- Вы начинаете с MasterViewController (Первый контроллер)
- После выбора или щелчка строки / ячейки загружается другой контроллер, содержащий списокпользователей?(Я не уверен), где каждый пользователь имеет информацию (содержащую userName, DOB и т. Д.).Таким образом, это означает, что в этом контроллере вы назначаете эту информацию соответствующим пользователям.(Второй контроллер)
- Затем, когда вы выбираете конкретного пользователя, другой контроллер загружается там, где вы хотите использовать данные с этого контроллера - возможно, именно здесь вы хотите отобразить эту информацию, назначенную вторым контроллером.(Третий контроллер)
Итак, если мы находимся на той же странице, вот что вы собираетесь сделать:
(Допустим, вы закончили с MainView (FirstController) и вы уже в SecondViewController)
Для начала вы можете сделать что-то вроде этого:
- Создайте глобальную переменную в ThirdViewController, которая будет содержать информациюпередан SecondViewController.В этом случае
///////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ///////// /////////~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ThirdViewController.h~~~~~~~~~~~~~~~~~~~~~~~~~~~ ///////// ///////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /////////
@interface ThirdViewController:UIViewController{
NSDictionary *dictInformation;
}
@property (nonatomic, retain) NSDictionary *dictInformation;
@end
@implementation ThirdViewController
@synthesize dictInformation;
...
// some codes here...
// you can use the information passed from the SecondViewController
...
- (void)dealloc{
[dictInformation release], dictInformation = nil;
[super dealloc];
}
@end
///////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ///////// ///////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SecondViewController.h ~~~~~~~~~~~~~~~~~~~~~~~~~ ///////// ///////// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /////////
@implementation SecondViewController
// This is the assignment of data. You can put this in viewDidload
// user 1
NSMutableDictionary *aUser1 = [[NSMutableDictionary alloc] init];
[aUser1 setObject:@"josh123" forKey:@"userName"];
[aUser1 setObject:@"01-01-1987" forKey:@"dateOfBirth"];
[aUser1 setObject:@"12345678" forKey:@"regNumber"];
[aUser1 setObject:@"24-H 1st St. New York" forKey:@"address"];
// user 2
NSMutableDictionary *aUser2 = [[NSMutableDictionary alloc] init];
[aUser2 setObject:@"josh321" forKey:@"userName"];
[aUser2 setObject:@"01-02-1988" forKey:@"dateOfBirth"];
[aUser2 setObject:@"87654321" forKey:@"regNumber"];
[aUser2 setObject:@"42-H 1st St. New York" forKey:@"address"];
// I assigned all users to an array
NSArray *arrayOfUsers = [[NSArray alloc] initWithObjects:aUser1, aUser2, nil];
[aUser1 release];
[aUser2 release];
// Pass the value of arrayOfUsers somewhere to that it can be accessed
// or it can be a
/* At this point, the following has values:
arrayOfUsers[0] = aUser1 -> {'josh123', '01-01-1987', '12345678', '24-H 1st St. New York'}
arrayOfUsers[1] = aUser2 -> {'josh321', '01-02-1988', '87654321', '42-H 1st St. New York'}
*/
// You can actually add the following codes anywhere, depending on your implementation. It can be when you clicked a cell or a button, etc.
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
// assign a dictionary value to dictInformation which is found in ThirdViewController
// If you are using UITableView, then, this should be done when you are selecting a cell in the tableView and the value of the index should be indexPath.row
[thirdViewController setDictInformation:[arrayOfUsers objectAtIndex:0]];
// This pushes to the ThirdViewController
[self.navigationController pushViewController:thirdViewController animated:YES];
[thirdViewController release];
...
@end
Примечание : Это всего лишь фрагмент кода ... Я просто хочу дать вам представление о том, как это сделать.Надеюсь, это поможет, хотя.Удачи!:)