Question

My cocoa app calculates the location of every mousedown event. It also checks whether the location is located inside a rectangle using NSPointInRect and while enumerating over an existing mutable array with values of the rectangles. I'm using an if-statement to add the rectangle values in which the mousedown event is located to a new array (selectedRectangles). The values are added perfectly to selectedRectangles, only problem is that previous values are overwritten. How can I solve this problem.

PS at the end of the mousedown method I use setNeedsDisplay:YES to update the data (this because selectedRectangles is used in another method).

Was it helpful?

Solution

add the rectangle values…to a new array

Assuming that you're asking a continuation of this question. You don't want to create a new array each time. You want to make an NSMutableArray before any click locations are stored, then use its addObject: method to add a new item on each click.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top