我有以下4个视图控制器:
我正在使用'Home - >的模态视图导航群组'和'群组 - >项目。现在,我想使用推送视图控制器'Items - >细节'。因为,我正在传递'群组 - >的群组ID项目'显示组特定项目。所以,'项目'是动态的。我不想为'详细信息 - >重现'项目'用于从详细信息返回项目的项目。
我怎样才能实现它?
修改
以下是显示项目页面的代码:
@implementation RpFoodList
@synthesize gid;
- (void)viewDidLoad
{
[super viewDidLoad];
[self loadFoodList];
}
- (void) loadFoodList
{
RpDb *rpDb = [[RpDb alloc] init];
int groupID = [self gid];
UIImage *iconLeft = [UIImage imageNamed:@"arrow_left.png"];
UIImage *iconLeftH = [UIImage imageNamed:@"arrow_left_h.png"];
UIButton *btnLeft;
UIButton *button;
UILabel *sep;
int bulletWidth = 40;
int rowHeight = 32;
NSMutableArray *foods = [rpDb getGroupFoods:groupID];
[groupTitle setText:[NSString stringWithFormat:@"Group Details (%d)", [foods count]]];
int counter = 0;
int contentSize = 0;
for(NSMutableDictionary *food in foods)
{
NSNumber *foodID = [food valueForKey:@"foodID"];
int tag = [foodID intValue];
NSNumber *groupID = [food valueForKey:@"groupID"];
NSString *foodName = [food valueForKey:@"foodName"];
NSString *foodNameAr = [food valueForKey:@"foodNameAr"];
btnLeft = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
btnLeft.frame = CGRectMake(0, rowHeight*counter+1, bulletWidth, rowHeight);
[btnLeft setImage:iconLeft forState:UIControlStateNormal];
[btnLeft setImage:iconLeftH forState:UIControlStateHighlighted];
[btnLeft addTarget:self action:@selector(showFoodDetails:) forControlEvents:UIControlEventTouchUpInside];
btnLeft.tag = tag;
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(bulletWidth, rowHeight*counter+1, self.view.frame.size.width-bulletWidth, rowHeight);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitle:foodNameAr forState:UIControlStateNormal];
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 10);
counter++;
contentSize += rowHeight + 1;
sep = [[UILabel alloc] init];
[sep setFrame:CGRectMake(0, rowHeight*counter+1, self.view.frame.size.width, 1)];
[sep setBackgroundColor: [UIColor lightGrayColor]];
[scrollView addSubview:button];
[scrollView addSubview:btnLeft];
[scrollView addSubview:sep];
}
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, contentSize);
}
- (IBAction)showFoodDetails:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
RpFoodDetails *foodDetails = (RpFoodDetails*)[storyboard instantiateViewControllerWithIdentifier:@"RpFoodDetails"];
foodDetails.fid = [sender tag];
foodDetails.gid = [self gid];
[self presentModalViewController:foodDetails animated:YES];
}
答案 0 :(得分:0)
根据我的理解,您需要组类和项类,并且从组中将组对象传递给项目并生成项目对象NSArray并填充UITable视图,然后将项目的同一对象传递到详细信息页面,当您从详细信息页面到项目页面所有项目都将以数组形式填充并填充,直到您返回组页面。
我从对问题的理解中回答
答案 1 :(得分:0)
根据我的理解,您有组的数组,其中包含项的数组。
NSMutableArray * foods = [rpDb getGroupFoods:groupID];
此行根据您的组ID返回项目数组。
所以在Items detail VC中,你需要传递来自Items VC的foodId。
要使其本质上是动态的,您需要在viewWillAppear中调用与数据库相关的操作。此外,还要从阵列中清除旧数据。