从DetailViewController发送数据到MasterViewController

时间:2013-04-07 13:16:43

标签: iphone objective-c xcode didselectrowatindexpath message-passing

这正是我想要做的。

wizardviewcontroller.m

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

用户单击国家/地区按钮,弹出窗口显示列表。

当用户选择行按钮标题时应该更改。

这是我的详细视图,

-(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正在解雇,但{​​{1}}没有更新。我知道这是因为wizardview不令人耳目一新。在这种情况下,我想知道正确的解决方法。

希望这有助于获得更好的答案。

1 个答案:

答案 0 :(得分:2)

MJDetailViewController

中制作协议
@protocol MJDetailViewControllerDelegate;
@interface MJDetailViewController : UIViewController
@property (nonatomic,assign) id< MJDetailViewControllerDelegate> delegate;
@end


@protocol MJDetailViewControllerDelegate <NSObject>

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

@end

并打电话给

-(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

中添加protocol作为WizardViewController.h

现在在selectedContry:中实施WizardViewController.m方法,例如:

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

希望它对你有所帮助。