Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7184009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:06:45+00:00 2026-05-28T18:06:45+00:00

I have a view that displays in a UIPopoverController. Before, it just had properties

  • 0

I have a view that displays in a UIPopoverController. Before, it just had properties that were associated with it’s view for a single object. So it would be something like

TargetDetailView : NSObject
@property Target *target

- (id)initWithTarget:(Target *)target

Now however, in some situations depending on what level zoom the user is looking at our view, there will be multiple targets in the popover. So I added an NSMutableArray *targets property to the class in order to show multiple targets in the popover.

Right now, the actual target objects that get drawn on our view are getting drawn on top of each other which is a waste.

The initWithTarget method only got called when you actually clicked on a target and the popover got presented.

What I’m trying to do now is calculate ahead of time where I am goign to have multiple targets in the same location, draw it only once, but when pressed have the popover show and this time, use the NSArray *targets to search through to show the multiple targets in that location.

The problem I have is I do not know where to initialize the memory for the NSMutableArray *targets. The TargetDetailView only gets initialized when you press the target, but I want to calculate ahead of time from my other class when the target views are on top of each other to only draw it once.

I sort my targets in order in terms of location, then I look to see if the first two are similar enough in location to bin them:

for (int i = 0; i < [sortedArray count] - 1; i++) {
    TargetDetailView *firstTargetDetailView = (TargetDetailView *)[sortedArray objectAtIndex:i];
    TargetDetailView *secondTargetDetailView = (TargetDetailView *)[sortedArray objectAtIndex:i + 1]; 

    if (secondTargetDetailView.target.location - firstTargetDetailView.target.location < scale) {
        [firstTargetDetailView.targets addObject:secondTargetDetailView.target]; // crash
        [newTargetDetailViewArray addObject:(TargetDetailView *)[sortedArray objectAtIndex:i]];

    }
}

I try to have the first TargetDetailView.target property point to the next TargetDetailView if it’s close enough in location. However, the .targets property never gets initialized since my TargetDetailView only gets initialized on press.

How should I either

a) allocate memory for this object
b) refactor and/or allocate memory for this object

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T18:06:46+00:00Added an answer on May 28, 2026 at 6:06 pm

    If I may make a suggestion, you could use the same initWithTarget method but always keep your targets in an array. You could then initialize your array there and add your Target parameter from the start, like this:

    @interface TargetDetailView :NSObject
    
    @property (nonatomic, retain) NSMutableArray *targets;
    
    - (id)initWithTarget:(Target *)target;
    
    @end
    
    
    @implementation TargetDetailView
    
    @synthesize targets;
    
    - (id)initWithTarget:(Target *)target {
        self = [super init];
        if (self) {
            targets = [[NSMutableArray alloc] initWithObject:target];
        }
        return self;
    }
    

    You can then use the targets property to add more targets (if you’d like) and use a simple loop through targets without having to care about the number of items in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a View that displays the Customer Details. I would like to display
I have a view that displays multiple images and those images' associated tags. I
I have a view that displays a list of models. Some of the properties
I have partial view that displays model-specific flash messages. The partial looks like: app/views/mymodel/_flashpartial.erb
I have just started my first CI app. I have a view that displays
I have an app that displays transcripts, something like this myapp.com/transcript/1234 The transcripts are
I have a partial view that displays a search options like search by category,
I have a table view that displays managed objects (Tasks). I'd like to fetch
I have a view that displays object information when the correct URL is provided
I have a Drupal view that displays vacation leaves for a particular employee. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.