1

這正是我正在嘗試做的。從DetailViewController發送數據到MasterViewController

wizardviewcontroller.m

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

用戶點擊按鈕全國彈出一個顯示了名單。

當用戶選擇一個行按鈕標題應該改變。

這是我的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被解僱,但countryButtonTitle沒有更新。我知道這是因爲wizardview並不令人耳目一新。我想知道在這種情況下正確的解決方法。

希望這有助於得到更好的答案。在MJDetailViewController

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


@protocol MJDetailViewControllerDelegate <NSObject> 

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

@end 

+1

您的代碼創建WizardViewController的* new *實例並在該新實例上設置屬性。您必須設置*現有*主視圖控制器的屬性。 – 2013-04-07 13:21:58

+0

我的主視圖控制器是WizardViewController – jack 2013-04-07 13:28:12

+0

不完全...它是** WizardViewController的一個實例。當你創建一個新的,它是一個不同的對象。 – 2013-04-07 13:31:19

回答

2

製作協議,並呼籲像

-(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]; 
} 

添加MJDetailViewControllerDelegate爲在WizardViewController.h

現在實現selectedContry:方法WizardViewController.m,如:

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

希望它可以幫助你。

+0

+1尼斯答案,我做了一些編輯。我希望你不會介意。 – viral 2013-04-08 07:23:10

相關問題