在我的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/