-1

I have created a bottom slide up view controller for a main view controller, but I'm not sure how to pass information from the main view controller to the slide up one. I have a button in the main view controller that can show or hide the slide up view controller, and I want to use the button to pass information. The code below is the IBAction for the button which would show/hide the slide up view controller, but without a segue I'm not sure how to pass anything.

- (IBAction)btnMoveToShowBottomView:(id)sender {
    UIButton *button = sender;

    switch (button.tag) {
        case 0:
            [_delegate moveToHideBottomTableView];
            break;

        case 1:
           BottomTableViewController *tableScreen = [[BottomTableViewController alloc]...];
        tableScreen.photoDesc = selectedPhotoDesc;
        [_delegate moveToShowBottomTableView];
            break;

        default:
            break;
    }
}

In the code above I've tried to access the slide up view controller (with a class called BottomTableViewController), but there seems to be a problem because it is asking for an expected expression when I attempt to access an object in that class (an NSString called photoDesc).

2
  • What is the [_delegate moveToShowBottomTableView] for? If you're trying to present a new view controller without a segue you should call presentViewController (the delegate shouldn't have to handle this). Regardless, the error you're getting sounds like it doesn't know where you're getting selectedPhotoDesc from. Jun 24, 2015 at 15:40
  • possible duplicate of Passing Data between View Controllers
    – JAL
    Jun 24, 2015 at 15:48

2 Answers 2

0

You can use NSNotification mechanism:

In a controller that has to get param register for notification:

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[NSNotificaitonCenter defaultCenter] addObserver: self selector:@selector(handleParam:) name:@"myNotification" object: nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)handleParam:(NSNotification*)notification
{
    if ([notification.name isEqualToString:@"myNotification")
    {
        id myParam = notification.object;
    }
}

In a controller that has to send a parameter:

[[NSNotificationCenter defaultCenter] postNotificationName:@"myNotification" object: myObject];
0

Two options: 1) https://medium.com/@jigarm/nsuserdefaults-iphone-objective-c-514febbbf29b

2) Have you tried passing

    self      

and

    selectedPhotoDesc 

to the function

    moveToShowBottomTableView 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.