Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-12-2010, 09:45 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 5
bobbiesimpson is on a distinguished road
Default NSNotification in sendEvent:

Hi everyone,

I'm trying to capture events on a MKMapView and I came across a thread which suggested that I subclass UIWindow, override the function sendEvent and post a notification within this function. Here it is Intercepting/Hijacking iPhone Touch Events for MKMapView - Stack Overflow

I have implemented it in my code as follows (this is my subclassed UIWindow)

CustomWindow.m
Code:
#import "CustomWindow.h"

@implementation CustomWindow

-(void)sendEvent:(UIEvent *)event
{
	[super sendEvent:event];
	
	//	let's send a notification off
	NSDictionary *dictionary = [NSDictionary dictionaryWithObject:event forKey:@"event"];
	NSNotification *note = [NSNotification notificationWithName:@"touchEvent" object:self userInfo:dictionary];
	[[NSNotificationCenter defaultCenter] postNotification:note];
	
	NSLog(@"notification sent");
	
}

@end
And I try to listen for this notification in a view controller as follows:

MapViewController.m
Code:
@implementation MapViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
		
		//let's listen for the touch notifications
		NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
		[nc addObserver:self selector:@selector(receivedTouchEvent:) name:@"touchEvent" object:nil];
    }
    return self;
}

-(void)receivedTouchEvent:(NSNotification *)note
{
	NSLog(@"mapView controller has received event");
	NSDictionary *userInfo = [note userInfo];
	NSLog(@"dictionary %@", userInfo);
}

- (void)dealloc {
    [super dealloc];
}

@end
The problem is that I don't receive the notifications in my view controller. Am I missing some fundamental point of NSNotification?
bobbiesimpson is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 346
10 members and 336 guests
cgokey, givensur, iGamesDev, jenniead38, linkmx, mraalex, PixelInteractive, raihan.zbr, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:01 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0