简体   繁体   English

将数据从DetailViewController发送到MasterViewController

[英]sending data from DetailViewController to MasterViewController

This is what exactly I'm trying to do. 这正是我想做的。

wizardviewcontroller.m 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. DetailViewController正在关闭,但是countryButtonTitle没有更新。 I know this is because the wizardview is not refreshing. 我知道这是因为WizardView没有刷新。 I would like to know the correct workaround in this case. 在这种情况下,我想知道正确的解决方法。

Hope this helps to get better answer. 希望这有助于获得更好的答案。

Make Protocol in MJDetailViewController 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 ) 添加MJDetailViewControllerDelegate作为protocolWizardViewController.h

Now implement selectedContry: method in WizardViewController.m like: 现在在WizardViewController.m实现selectedContry:方法, WizardViewController.m所示:

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

Hope it helps you. 希望对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据发送到detailViewController无法正常工作? - Sending data to detailViewController not working? UISplitViewController:在iPhone上的detailViewController中导航后显示masterViewController - UISplitViewController: Show masterViewController after navigation in detailViewController on iPhone 从plist加载到detailviewcontroller中的数据? - load data in detailviewcontroller from plist? 无法从MasterViewController识别UISplitViewController选择器 - UISplitViewController selector not recognized from MasterViewController 如果用户在查看MasterViewController时旋转,则DetailViewController的Master-Detail App自动旋转未对齐 - Master-Detail App Autorotation for DetailViewController not aligned if user rotates while viewing MasterViewController 如何从RootViewController禁用DetailViewController UIBarButtonItem? - How to disable a DetailViewController UIBarButtonItem from RootViewController? Obj-C:从导航控制器中的detailViewController返回参数 - Obj-C : Passing parameters back from a detailViewController in a navigation controller 如何从DetailViewController中选定的单元格获取cell.textLabel.text? - How to get the cell.textLabel.text from the selected cell in DetailViewController? 从导航堆栈中较低级别的rootviewcontroller访问DetailViewController - Accessing DetailViewController from lower levels of rootviewcontroller in a navigation stack iOS - DetailViewController不显示来自JSON的多个条目/值 - iOS - DetailViewController not displaying multiple entries/values from JSON
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM