1

2 つの Viewcontroller 間で委任を使用しようとしていますが、残念ながら私の委任は解雇されません。誰かが私が問題を解決するのを手伝ってくれることを願っています. MapBackgroundViewController と呼ばれる ViewContoller と MapsViewController と呼ばれる ViewContoller があります。MapsBackgroundViewController の SegmentedControl が変更された場合、MapsViewController に通知する必要があります。(私は実際に家系カールでiPhoneの地図アプリのようなものを実装しようとしています)

ここに私のコードの一部があります:

MapBackgroundViewController.h

@protocol ChangeMapTyp <NSObject>
@required
- (void)segmentedControllChangedMapType:(MKMapType) type ;
@end


@interface MapBackgroundViewController : UIViewController{
IBOutlet UISegmentedControl *segmentedControl;
MKMapType mapType;
id < ChangeMapTyp> delegate;

}


@property IBOutlet UISegmentedControl *segmentedControl;

@property MKMapType mapType;

@property(strong)id delegate;

- (IBAction)segmentedControllChanged:(id)sender;

MapBackgroundViewController.m

@interface MapBackgroundViewController ()

@end

@implementation MapBackgroundViewController
@synthesize segmentedControl, mapType, delegate;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

[self setDelegate:self];

NSLog(@"%@",self.delegate);

}


- (IBAction)segmentedControllChanged:(id)sender {

if (segmentedControl.selectedSegmentIndex == 0) {
    mapType = MKMapTypeStandard;
}else if (segmentedControl.selectedSegmentIndex == 1) {
    mapType = MKMapTypeSatellite;
} else if (segmentedControl.selectedSegmentIndex == 2) {
 //   [self.delegate setMapType:MKMapTypeHybrid];
    mapType = MKMapTypeHybrid;
}


//Is anyone listening

NSLog(@"%@",self.delegate);

if([self.delegate respondsToSelector:@selector(segmentedControllChangedMapType:)])
{
    //send the delegate function with the amount entered by the user
    [self.delegate segmentedControllChangedMapType:mapType];
}

[self dismissModalViewControllerAnimated:YES];

}

MapsViewController.h

#import "MapBackgroundViewController.h"

@class MapBackgroundViewController;

@interface MapsViewController : UIViewController<MKMapViewDelegate,
UISearchBarDelegate,  ChangeMapTyp >{
 IBOutlet MKMapView *map;
}


@property (nonatomic, retain) IBOutlet MKMapView *map;


@end

MapsViewController.m (何らかの理由で以下のメソッドが呼び出されない)

 - (void)segmentedControllChangedMapType: (MKMapType) type{
    map.mapType = type;
 }
4

1 に答える 1

6

プロパティをにMapBackgroundViewController設定したため、デリゲートは- ( )なので、チェックを実行すると が返されます。をデリゲートにしたい場合は、 のインスタンスを持っている必要があり(たとえば、呼び出されます)、次に.delegateselfselfMapBackgroundViewControllerif([self.delegate respondsToSelector:@selector(segmentedControllChangedMapType:)])NOself.delegateselfMapBackgroundViewControllerMapsViewControllerMapBackgroundViewControllerMapsViewControllermyMapsViewControllerself.delegate = myMapsViewController

于 2012-05-20T11:52:28.467 に答える