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 8946801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:35:41+00:00 2026-06-15T12:35:41+00:00

I currently have a custom view class which is drawing a 2d game board

  • 0

I currently have a custom view class which is drawing a 2d game board representation on a window.

When the user clicks on the board I am using the mouseDown: event to calculate the cell co-ordinates from the mouse position (I am doing this within the custom view class).

- (void)mouseDown:(NSEvent*)theEvent {

    // Get position of mouse click:
    NSPoint point = [theEvent locationInWindow];
    NSPoint mousePos = [self convertPoint:point fromView:nil];

    // Calculate which cell has been clicked:
    int cellX = mousePos.x / gridSize.width;
    int cellY = mousePos.y / gridSize.height;

}

(In the above snippet ‘gridSize’ is an NSPoint instance variable that I am using to store the height and with of each cell in the game board)

Is it possible for me to create an IBAction style message in my controller class that can be used to send this information?

The way I was imagining this could work was:

  • Declare instance variables for clicked co-ordinates in the custom view.
  • Implement an (IBAction) in the controller class:
  • Use the (id)sender pointer to access the instance variables that hold the co-ordinates
  • Link the IBAction to the custom view in interface builder

To try this I declared ‘cellX’ and ‘cellY’ as instance variables in my custom view. I then implemented the following in my controller class:

-(IBAction)cellClicked:(id)sender { 

    [self setCellAtPosX:[sender cellX] PosY:[sender cellY];
}

(cellX and cellY are accessor methods to the instance variables)

As I was expecting it is not that simple, and it will not let me link the IBAction to the custom view. Is there anything missing from my approach to implementing this?

I can imagine that all this would need is some kind of notifier that tells interface builder where to send out a target-action message – in my case, at the end of the mouseDown: implementation, but I cannot find where to begin with this!

  • 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-06-15T12:35:41+00:00Added an answer on June 15, 2026 at 12:35 pm

    You may have less trouble implementing this with a delegate pattern, i.e. set a IBOutlet delegate property on your board view and have the controller implement this protocol. In Interface Builder you will link your view and controller via the outlet, and the view will call it’s delegate method in the mouseDown implementation, for instance:

    - (void)mouseDown:(NSEvent*)theEvent {
       ...
       [self.delegate boardView:self didSelectCellAtX:x Y:y];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a custom TabItem which has a custom header, which is defined
I currently have a need for a custom ListViewItem class - let's call it
Currently, I'm trying to have a top-level window in Windows Forms with a custom
I have implemented a custom split view controller which — in principle — works
I have a custom view (which extends GLSurfaceView) I'm trying to use in my
I have a custom DownloadFiles class which extends AsyncTask . The app launches itself
I have a custom view class called TextFieldView and it's initialized from a nib...
I have a view model which uses custom attributes such as public int Id
I'm looking into some XSS prevention in my Java application. I currently have custom
I currently have a custom themed blog running on wordpress with Jetpack installed. 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.