I have seen many threads related to this problem, but no one is addressing my case (I think).
My case should be simple, I have a custom UIView in my controller, from my controller I use [ self.myView setNeedsDisplay ], and it works fine.
I am having problems when I try to call this from within the UIView itself ... I have a notification sent from another class and it is received by my view (this works) with the information it passes, I update the internal properties of this view, and I call [self setNeedsDisplay ], wanting to update my screen with new states, but nothing happens, I used the NSLOG inside my drawRec method, and it is not called at this time, it is called only when my controller class calls setNeedsDisplay , and when it happens update which should have happened earlier, displayed on the screen ... I do not know why it should not be updated to ...
Here is the code:
My controller is requesting an update: (works fine!)
- (void)addNodeToNetwork:(DTINode *)node { [self.myNetwork addNodeInTheNetwork:node]; self.gridView.nodesToDraw = [self.myNetwork.nodesInNetwork copy]; CGRect tempRec = CGRectMake(node.nodePosition.x, node.nodePosition.y node.nodePosition.x, node.nodePosition.y); NSValue *rectObj = [NSValue valueWithCGRect:tempRec];
My notification method is trying to update my drawing: (Not working!)
- (void) receiveTestNotification:(NSNotification *) notification { NSDictionary *userInfo = notification.userInfo; DTINode *notificationNode = [userInfo objectForKey:@"myNode"]; NSLog(@"Im Here!"); for (DTINode *node in self.nodesToDraw) { NSLog(@"Here too"); if(node.nodeName == notificationNode.fatherNode) { CGRect temp = CGRectMake(notificationNode.nodePosition.x, notificationNode.nodePosition.y, node.nodePosition.x, node.nodePosition.y); NSValue *tempObj = [NSValue valueWithCGRect:temp]; [self.fatherNodes setObject:tempObj forKey:notificationNode.nodeName]; [self setNeedsDisplay]; NSLog(@"Should REDRAW NOW!");
I do not insert my drawRect here because it works, the problem is that it is not called from inside my UIView setNeedsDisplay !
Does anyone have an idea why this is not working?
Plauto abreu
source share