在我的MasterViewController
uitabelview
中,选择方法会更改DetailedViewController
视图。
我的问题是当我更改DetailedViewController
中的视图时,如果用户未手动保存,则需要保存文本字段值。
我如何从MasterViewController
检查此内容,或者检测主视图的任何想法都选择了从DetailedViewController
调用的方法。
提前感谢。
答案 0 :(得分:1)
在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
}