편집 : 첫 번째보기에서 음식 항목의 목록을 표시하려는 것 같습니다. 항목을 누르면 상세보기가 열립니다. 세부 뷰에서 사용자는 단추를 눌러 식사에 추가 할 수 있습니다. 결국, 첫 번째보기에서 단추를 눌러 식사보기를 열 수 있습니다.이보기에는 선택한 모든 항목이 들어 있어야합니다.
이 경우 첫 번째보기 컨트롤러에 배열을 유지하고 세부 (두 번째)보기 컨트롤러에 첫 번째보기 컨트롤러에 대한 참조가 있는지 확인하십시오. 이렇게하면 해당 배열을 사용할 수 있습니다. 건축가이 더 나은 방법이 있습니다,하지만 지금은 작동합니다 : 상세 뷰가 제공됩니다
@interface FoodListViewController : UIViewController
@property (strong, nonatomic) NSMutableArray *foodItems
@end
@implementation FoodListViewController
- (void)showFoodItem
{
FoodItemDetailViewController *detailViewController = [[FoodItemDetailViewController alloc] initWithNibName:nil bundle:nil];
detailViewController.foodListController = self;
[self presentModalViewController:detailViewController animated:YES];
}
@end
되면, 배열에 현재의 'mealItem'을 추가해야한다 '추가 식사'버튼을 눌러. 귀하의 예제에서, 당신은 문자열을 사용하고 있습니다 - 당신이 오히려 어떤 이유로 문자열의 배열을 유지한다면, 나는 당신에게 맡길 것입니다. 두 번째와 세 번째 뷰 컨트롤러는 제시,
@interface MealDetailsViewController : UIViewController
@property (nonatomic, strong) NSArray *foodItems;
@end
@implementation MealDetailsViewController
// Set foodItems before this view controller is presented, then use it to drive the
// UITableView data source, or find some other way of displaying it.
@end
당신이 볼 수 있듯이 : 그것은 MealDetailsViewController을 제시하는 시간을 때
마지막으로
@interface FoodItemDetailViewController : UIViewController
@property (nonatomic, weak) FoodItemsViewController *foodListController;
@end
@implementation FoodItemDetailViewController
- (IBAction)buttonTapped:(id)sender
{
[self.foodListController.foodItems addObject:self.mealItem];
// Update the UI to let the user know that the item was added to the meal
}
@end
, 그냥 당신이 건물왔다 배열을 전달 첫 번째로. View 컨트롤러는 (거의) 항상 계층 구조를 형성합니다. 따라서 해당 계층의 맨 위에있는 데이터를 FoodListViewController에 저장하여 유지하면 다른 뷰 컨트롤러를 제시 할 때 계층 구조를 깔끔하게 전달할 수 있습니다.
출처
2012-12-06 21:33:45
Tim
instanciating중인보기 컨트롤러에 연결된 펜촉이 있습니까? – tiguero
selectedMenuItem이 View Controller 중 하나의 속성이 아닌 이유는 무엇입니까? – tiguero
죄송하지만 펜촉 파일을 만드는 방법을 모르겠습니다. 이걸 좀 도와 주실 래요? –