Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何以编程方式使用推送视图导航?_Ios_Pushviewcontroller - Fatal编程技术网

Ios 如何以编程方式使用推送视图导航?

Ios 如何以编程方式使用推送视图导航?,ios,pushviewcontroller,Ios,Pushviewcontroller,我有以下4个视图控制器: 家 组 项目 细节 我正在使用“主页->组”和“组->项目”的模式视图导航。现在,我想使用“项目->详细信息”的推式视图控制器。因为,我正在传递“组->项目”的组id以显示组特定的项目。因此,“项目”是动态的。我不想为“详细信息->项目”复制“项目”,以便从详细信息返回到项目 我怎样才能做到呢 编辑 以下是显示项目页面的代码: @implementation RpFoodList @synthesize gid; - (void)viewDidLoad { [

我有以下4个视图控制器:

家 组 项目 细节 我正在使用“主页->组”和“组->项目”的模式视图导航。现在,我想使用“项目->详细信息”的推式视图控制器。因为,我正在传递“组->项目”的组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];
}

根据我的理解,这很简单,您需要group类和items类,从group中,您将group对象传递给items,生成item对象NSArray并填充UITable视图,然后将相同的item对象传递给detail页面,当您从detail页面返回items页面时,所有项目都将在数组中,并为您填充,直到返回组页面


根据我对问题的理解,我的回答是,根据我的理解,您有一个由项目数组组成的组数组

NSMutableArray*foods=[rpDb getGroupFoods:groupID]

此行返回基于组id的项目数组

所以在Items detail VC中,您需要从Items VC传递foodId


要使其在本质上是动态的,您需要在ViewWillDisplay中调用与数据库相关的操作。此外,还要清除阵列中的旧数据。

您是说,当您从详细信息返回时,您担心您不知道要显示哪些项目?如果这是您关心的问题,则不会成为问题,因为视图控制器仍在堆栈中。我无法理解您的问题。是的。当我从“详细信息”返回到项目时,会出现空白屏幕。我使用了“导航栏”和“栏按钮项”作为后退按钮。@Mosiur在项目VC的ViewWillDisplay或ViewDidDisplay中发生了什么?您是通过调用WS还是通过DB重新加载项目?显示您的代码。@Amar我已编辑问题以提供代码。请查收。