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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:40:50+00:00 2026-06-16T05:40:50+00:00

I am in ViewController, trying to access a method in object cat owned by

  • 0

I am in ViewController, trying to access a method in object “cat” owned by object “backgroundpicture”. ViewController has an instance of backgroundpicture.

The method/message in “cat.h”:

@interface Cat : NSObject
    -(BOOL)checkIfTouchHit:(float) xx :(float) yy; 
@end

“Cat.m”:

- (BOOL)checkIfTouchHit:(float) xx :(float) yy{
    NSLog(@"Inside checkIfTouchHit");
    return YES;
}

“BackGroundPicture.h”:

#import "Cat.h"

@interface BackGroundPicture : NSObject
    @property (strong) Cat * katt;
@end

“BackGroundPicture.m”:

@implementation BackGroundPicture
    @synthesize katt = _katt
@end

“ViewController.m”:

@interface ViewController ()
@property (strong) BackGroundPicture * bakgrunnsbilde;
@end

@implementation BackGroundPicture
@synthesize bakgrunnsbilde = _bakgrunnsbilde;
- (void)viewDidLoad
{...
[[self.bakgrunnsbilde katt] checkIfTouchHit :(float)touchLocation.x :(float)touchLocation.y]   
...}

The string inside the method “checkIfInside” in cat will not show up. I also tried
[_bakgrunnsbilde katt]…
but with the same lack of result, and I believe this is compiled the same way. I am wondering what I am missing here, and hope someone can help. Thanks 🙂

edit I forgot to add a few lines from my BackGroundPicture.m. It is a method run on start from the ViewDidLoad in ViewController. It is like this in BackGroundPicture.m:

- (void)createObjects {    
Cat * katt = [[Cat alloc] init];
}

it is called from ViewController.m like so:

- (void)viewDidLoad
{
[_bakgrunnsbilde createObjects];
}

I know that this get executed. I hope this edit makes sense, my head is ruined after a long day 🙂 Going to check back tomorrow morning.

  • 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-16T05:40:52+00:00Added an answer on June 16, 2026 at 5:40 am

    It will work, but BackGroundPicture.m needs to allocate a cat first.

    So in BackGroundPicture.m, do this:

    - (id)init {
    
        self = [super init];
        if (self) {
            _katt = [[Cat alloc] init];
        }
        return self;
    }
    

    In general, remember to allocate objects before you use them. You may also need to create a BackGroundPicture, too as Valentin points out. In viewDidLoad, do this:

    bakgrunnsbilde = [[BackGroundPicture alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a logic issue. I need to access an instance of an object
I am trying to access properties of an object (person's firstName) which is stored
I am trying to call a method that returns an object and need help
I'm setting a string in a view controller called ViewController and trying to access
I am trying to send a simple string from One viewcontroller to another viewcontroller
I have a couple UIViewControllers that I am trying to access an array inside
This is the first time I'm trying to create and access a SQLite db
I am new to iOS. I am trying to set a bool in a
I am trying to print/access my (double) value from a JSON call and get:
I'm trying to share an NSArray object between several different view controllers and my

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.