2

I have a UIView that I import to display bezier paths with setNeedsDisplay from the super class.

I need to call another method in the super class once the UIView has finished updating. I call the method after setNeedsDisplay however the method is called before UIView has completed redrawing.

As a quick-fix I created an NSTimer with 0.3 seconds before calling the method. That works but could be unreliable. I could also post a notification from the UIView back to the super class but that just seems not right.

I've checked the documentation but can't find anything about a completion notification. Is there any built-in function for this?

Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
PaulMrG
  • 1,822
  • 2
  • 16
  • 20
  • how about calling that other method at the end of `drawRect`'s body? – vikingosegundo Aug 18 '13 at 12:32
  • May be when you registered on notification, you use incorrect observer? – Kepler Aug 18 '13 at 12:36
  • drawRect is in the imported class, I need to call the method that is within the super class, as far as I know you can't do that? – PaulMrG Aug 18 '13 at 12:38
  • I don't know the answer to your question, but `drawRect:` does nothing except what you implement. (The Docs: "The default implementation of this method does nothing"). Maybe you should be looking at the `UIViewController` methods like `viewDidLayoutSubviews`. – nevan king Aug 18 '13 at 12:54

2 Answers2

2

You can declare a new method

- (void)setNeedsDisplayCompletion:(MYCompletion)completion;

but before that declare typedef

typedef void((^MYCompletion)());

then implement it

- (void)setNeedsDisplayCompletion:(MyCompletion)completion {
    self._completion = [completion copy];
    [self setNeedsDisplay];
}

then use completion block in drawRect

[super drawRect:rect];
if (self._completion) {
    self._completion();
}

P.S. _completion is a property

@property (nonatomic, strong) MyCompletion _completion;

Now you can use your new method

[self._uiTextView setNeedsDisplayCompletion:^{
    [self setNeedsLayout];
}];
Philip J. Fry
  • 1,165
  • 1
  • 8
  • 10
0

Sorry, if I my answer is some incorrect (my english is not so good). Try to declare your super view's method who's reloading uiview (with bizier paths) and change code, when you post notification on code, when you will call that method. Or just try to

[superView performSelectpr:@selector(reloadSubview)];
Kepler
  • 705
  • 1
  • 5
  • 19
  • That's not going to work if I use the UIView in other classes. Tried it anyway just now but it won't let me declare the class in the header, gives 'Unknown type name' error. – PaulMrG Aug 18 '13 at 12:49
  • Sorry, I cant offer more – Kepler Aug 18 '13 at 12:52