DetailedViewController

DetailedViewController

在我的MasterViewController uitabelview中,选择方法更改了DetailedViewController视图。

我的问题是当我更改DetailedViewController中的视图时,如果用户未手动保存,则需要保存文本字段值。

我怎么能从MasterViewController检查这个或检测主视图的任何想法确实选择了从DetailedViewController调用的方法。

提前致谢。

最佳答案

在您的MasterViewController.h

@protocol CellSelectionDelegate <NSObject>

     -(void)rowSelected:(NSIndexPath *)indexPath;
@end


@interface MasterViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
}
@property(nonatomic,strong)IBOutlet UITableView *menuTable;
@property (nonatomic, weak) id<CellSelectionDelegate> cellDelegate;

@end


在您的MasterViewController.m

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([self.cellDelegate respondsToSelector:@selector(rowSelected:)])
    {
        //sending selected indexPath, you can use indexPath.row in your detail view
        [self.cellDelegate rowSelected:indexPath];
    }

}


现在在您的DetailedViewController.h

#import "MasterViewController.h"
@interface DetailedViewController : UIViewController<CellSelectionDelegate>
{

}
@property(nonatomic,strong)MasterViewController *masterView;
@end


DetailedViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Set master page as the delegate.
    masterView.delegate = self;

}


现在声明以下委托方法

-(void)rowSelected:(NSIndexPath *)indexPath
{
    NSLog(@"Your selected Row : %d",indexPath.row);
    //do your work according to selection made in master view. use indexpath.row to identify which option was selected, you can also pass the other data with rowselected: method
}

关于ios - 在拆分 View Controller 中:从主 View Controller 调用详细 View Controller 方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32962768/

10-12 23:52