这样做的正确方法?重用相同的故事板视图和视图控制器

时间:2016-09-22 15:50:22

标签: ios objective-c storyboard

我在做如下。我们的想法是根据菜单按钮提供的类型传递不同的值并显示数据。

但它没有按预期工作。 它只是显示首先调用哪个视图(或者在第二个按钮按下时不刷新数据显示第一个视图)。 那么这样做的正确方法是什么?

if (indexPath.row == 1) {
    SomeViewController* v = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboardCat"];
    v.type=@"1";
    [self showViewController:v];
    [self.slidingViewController resetTopViewAnimated:YES];
}

if (indexPath.row == 2) {
    SomeViewController* v = [self.storyboard instantiateViewControllerWithIdentifier:@"storyboardCat"];
    v.type=@"2";
    [self showViewController:v];
    [self.slidingViewController resetTopViewAnimated:YES];
}

编辑 - 了解更多信息 SomeViewController.h文件

@interface SomeViewController : UIViewController
@property (nonatomic, strong) NSString *type;
@end

SomeViewController.m文件

@implementation SomeViewController
@synthesize type;
arrayData = [NSMutableArray arrayWithArray:[CoreDataController getSomeData:type]];

//so trying to populate different values in tableview based on passed parameter to function

但是现在哪个视图被调用为first或者值被传递(1或2),只有那些值被填充,并且值不会在同时调用时传递另一个值(例如,当index row为2时)。

1 个答案:

答案 0 :(得分:0)

试试这个

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil]; //Change Main if your storyboard name is different.
    SomeViewController* v = [storyboard instantiateViewControllerWithIdentifier:@"launchView"]; // launchView is the name given to the view controller in the properties as shown in below screenshot

enter image description here

希望这有帮助