我试图在两个视图之间传递一个整数。当我从 View1 返回到 MainView 时,该值未传递,并且 NSLog(@"Changed map") 未显示在控制台中。我寻找答案并尝试了所有方法,但它不起作用!感觉代言人有问题……
有任何想法吗?
View1.h
@class FlipsideViewController;
@protocol FlipsideViewControllerDelegate
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller;
-(void)flipsideViewControllerSelectionChangedToIndex:(int)index;
@end
@interface FlipsideViewController : UIViewController {
}
@property (weak, nonatomic) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, retain) IBOutlet UISegmentedControl *mapType;
- (IBAction)valueChangedMap:(id)sender;
@end
查看1.m
-(IBAction)valueChangedMap:(id)sender {
[self.delegate flipsideViewControllerSelectionChangedToIndex:[sender selectedSegmentIndex]];
NSLog (@"%d",[sender selectedSegmentIndex]);
[self dismissViewControllerAnimated:YES completion:nil];
}
主视图.h
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate, UIPopoverControllerDelegate, MKMapViewDelegate> {}
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@property(weak) id<FlipsideViewControllerDelegate> delegate;
@end
主视图.m
-(void)flipsideViewControllerSelectionChangedToIndex:(int)index {
NSLog(@"Changed map");
if (index == 0) mapView.mapType = MKMapTypeStandard;
if (index == 1) mapView.mapType = MKMapTypeHybrid;
if (index == 2) mapView.mapType = MKMapTypeSatellite;
}