1

I've got a really annoying issue at the moment while trying to create an overlay to provide a greyed out interface when searching and then when it's touched dismiss it.

I've adapted some code from another part of my app and to me they are completely the same, expect the variable name changes etc.

Here's the two header files for comparison

Contacts search overlay:

#import <UIKit/UIKit.h>
@class Contacts;
@interface Overlay : UIViewController{
    Contacts *Contact;
}
@property(nonatomic,retain) Contacts *Contact;
@end

Map search overlay:

#import <UIKit/UIKit.h>
@class Map;
@interface mapOverlay : UIViewController{
    Map *searcher;
}
@property(nonatomic,retain) Map *searcher;
@end

And the two method files for comparison

Contacts search overlay:

#import "Overlay.h"
#import "Contacts.h"
@implementation Overlay
   @synthesize Contact;
   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      [Contact doneSearching_Clicked:nil];
   }
   - (void)dealloc {
      [Contact release];
      [super dealloc];
   }
@end

Map search overlay:

#import "mapOverlay.h"
#import "Map.h"
@implementation mapOverlay
    @synthesize searcher;
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [searcher doneSearching_Clicked:nil];
    }
    - (void)dealloc {
       [searcher release];
       [super dealloc];
    }
@end

So both of them are exactly the same, and are calling the same function.

Here's the headers for the Contacts and Map classes

Contacts

#import <UIKit/UIKit.h>
@class Overlay;
@interface Contacts : UIViewController <NSXMLParserDelegate , UISearchBarDelegate>{
     Overlay *searchOverlay;
}
- (void)doneSearching_Clicked:(id)sender;
@end

Map

#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@protocol ModalViewDelegate

- (void)didReceiveMessage:(NSString *)message fromwho:(NSInteger )whichText;

@end
@class mapOverlay;
@interface Map : UIViewController<MKMapViewDelegate,NSXMLParserDelegate, ModalViewDelegate> {
    mapOverlay *searchOverlay;
}
- (void)doneSearching_Clicked:(id)sender;
@end

I'm really stumped with this. I'm pretty sure that I've done nothing wrong as both implementations are exactly the same. The only difference is that the Map class has a delegate for a modalview. I've taken this out and tried but still no luck.

I've checked to make sure that both views are registering the touches which they are. It just appears that the overlay used for the map is not sending the message to the Map class.

Does anyone have an idea what could be causing it work in one but not the other?

  • 5
    A couple things... it's standard Objective-C convention to name your objects with lower cases (i.e. change `Contact * Contact` to `Contact * contact;`). If you set a breakpoint on your touch method, is your `searcher` object NULL when you are attempting to send a message to it? I have a feeling it is... :-) – Michael Dautermann Dec 04 '11 at 01:24
  • yes it is, I read that it may be that the class wasn't initiated so I tried this and had no luck. I've tried `next responder` and it said Map but no way to access the `doneSearching_clicked` method within it. –  Dec 04 '11 at 16:24
  • "yes it is", as in yes it *is* null? If so, you need to instantiate it or find a way to link it up to your 'searcher' object. – Michael Dautermann Dec 04 '11 at 16:49
  • Sorry, yes it does return null. I've added `[[Map alloc] init];` to the mapOverlays `viewDidLoad`. This is now working thanks. Although for some reason it's now not executing the commands in the `doneSearchingClicked` so not sure what's happening there. –  Dec 04 '11 at 20:07

0 Answers0