1

This is what exactly I'm trying to do.

wizardviewcontroller.m

- (IBAction)onCountryClick:(id)sender {
    MJDetailViewController *detailViewController = [[MJDetailViewController alloc] initWithNibName:@"MJDetailViewController" bundle:nil];
    [self presentPopupViewController:detailViewController animationType:MJPopupViewAnimationSlideLeftRight];
}

User click country button a popup shows with list.

when user select a row button title should change.

This is my detailview,

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath     *)indexPath {

    WizardViewController *mj = [[WizardViewController alloc]       initWithNibName:@"WizardViewController" bundle:nil];
    mj.countryselected = [countryNames objectAtIndex:indexPath.row];
    [mj.countryButton setTitle:mj.countryselected forState:UIControlStateNormal];
    [self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}

DetailViewController is dismissing, but countryButtonTitle is not updating. I know this is because the wizardview is not refreshing. I would like to know the correct workaround in this case.

Hope this helps to get better answer.

jack
  • 73
  • 1
  • 10
  • 1
    Your code creates a *new* instance of WizardViewController and sets a property on that new instance. You have to set the properties of your *existing* master view controller. – Martin R Apr 07 '13 at 13:21
  • my master view controller is WizardViewController – jack Apr 07 '13 at 13:28
  • Not exactly...it's **an instance of a** WizardViewController. When you create a new one, it's a different object. – Phillip Mills Apr 07 '13 at 13:31
  • possible duplicate of [What's the best way to communicate between view controllers?](http://stackoverflow.com/questions/569940/whats-the-best-way-to-communicate-between-view-controllers) – Carl Veazey Apr 08 '13 at 04:54
  • You should use protocol in detail view and set master as delegate. See Utility app for example. – pbibergal Apr 07 '13 at 15:35

1 Answers1

2

Make Protocol in MJDetailViewController

@protocol MJDetailViewControllerDelegate;
@interface MJDetailViewController : UIViewController
@property (nonatomic,assign) id< MJDetailViewControllerDelegate> delegate;
@end


@protocol MJDetailViewControllerDelegate <NSObject>

- (void)selectedContry:(NSString *)title;

@end

And call like

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath     *)indexPath {

    NSString *title = [countryNames objectAtIndex:indexPath.row];
       if ([self.delegate respondsToSelector:@selector(selectedContry:)]) {
            [self.delegate selectedContry:title];
        }
    [self dismissPopupViewControllerWithanimationType:MJPopupViewAnimationFade];
}

Add MJDetailViewControllerDelegate as a protocol in WizardViewController.h)

Now implement selectedContry: method in WizardViewController.m like:

- (void)selectedContry:(NSString *)title
{
    [self.countryButton setTitle:title forState:UIControlStateNormal];
}

Hope it helps you.

viral
  • 4,168
  • 5
  • 43
  • 68
chirag
  • 1,090
  • 9
  • 13