0

I have these lines of code:

-(void)someMethod:(UIScrollView*)scrollView{
 [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(keyboardWasShown:)
     name:UIKeyboardDidShowNotification object:nil];
}
-(void)keyboardWasShown:(NSNotification *)aNotification{
// I want to get scrollView over here
}

Is there a way to make this possible? I've tried to perform this staff according to

How to pass a NSDictionary with postNotificationName:object:

but aNotification.userInfo doesn't contain my data

  [[NSNotificationCenter defaultCenter] 
postNotificationName:UIKeyboardDidShowNotification 
object:self
 userInfo:@{@"scrollView":scrollView}];
Community
  • 1
  • 1
O.G.O
  • 149
  • 1
  • 9

1 Answers1

0

You are listening to UIKeyboardDidShowNotification and then you post UIKeyboardWillHideNotification that won't work. First maybe you like create your own notification name i.e XYZKeyboardDidShowNotification and then register for that and post using that name with the additional data you want. And then you can do:

-(void)keyboardWasShown:(NSNotification *)aNotification{
    UIScrollView *scrollView = aNotification.userInfo[@"scrollView"];
}
Peter Segerblom
  • 2,773
  • 1
  • 19
  • 24
  • Is there a way to use default UIKeyboardDidShowNotification? – O.G.O Aug 03 '15 at 08:51
  • Well. Your answer can't help with my question because question was really dumb. Thanks to you I've made own custom notification and have found mistakes in architecture of my classes. – O.G.O Aug 03 '15 at 10:21