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

  • Home
  • SEARCH
  • 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 3354100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:13:53+00:00 2026-05-18T02:13:53+00:00

I’m new to Objective-C and iPhone SDK development. I want to call a method

  • 0

I’m new to Objective-C and iPhone SDK development. I want to call a method in the same class:

- (void) setFilePath:(NSString *) p
{
  [self methodCall];
}

- (void) methodCall
{
  fileContent.text = @"Test"; //fileContent is a UITextView
}

If the property “filePath” is set, the method “setFilePath” is called. Then the UITextView, created in IB, should display the text. But that doesn’t work …

If I call the method directly via button in IB, then the UITextView changes his content successfully:

- (IBAction) clickButton
{
  fileContent.text = @"Test";
}

What could be the problem?

Thanks for your answers!

EDIT 2: I solved the problem by setting “filePath” after pushing the view:

- (IBAction) showFileContent {

FileContentsViewController *fileContentsViewController = [[FileContentsViewController alloc] init];
[self.navigationController pushViewController:fileContentsViewController animated:YES];
fileContentsViewController.filePath = self.filePath;
fileContentsViewController.title = [NSString stringWithFormat:@"Content from von %@", [filePath lastPathComponent]];
[fileContentsViewController release];

}

EDIT 1: Here’s the code of my interface:

@interface FileContentsViewController : UIViewController {

NSString *filePath;
UITextView *fileContent;

}

- (void) methodCall;

@property (nonatomic, retain) NSString *filePath;
@property (nonatomic, retain) IBOutlet UITextView *fileContent;

@end

… and here’s the code of the implementation:

#import "FileContentsViewController.h"


@implementation FileContentsViewController

@synthesize filePath;
@synthesize fileContent;

- (void) setFilePath:(NSString *) p
{
    NSLog(@"setFilePath executed!");
    [self methodCall];
} 

- (void) methodCall
{
    fileContent.text = @"Test"; // UITextView
}

// some standard methods

@end

… and finally the code of the method that sets “filePath”:

- (IBAction) showFileContent {

FileContentsViewController *fileContentsViewController = [[FileContentsViewController alloc] init];
fileContentsViewController.filePath = self.filePath;
fileContentsViewController.title = [NSString stringWithFormat:@"Content from von %@", [filePath lastPathComponent]];
[self.navigationController pushViewController:fileContentsViewController animated:YES];
[fileContentsViewController release];

}
  • 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-18T02:13:53+00:00Added an answer on May 18, 2026 at 2:13 am

    What it looks like is that the fileContentsViewController created in -showFileContent doesn’t have anything assigned to its FileContentsViewController.fileContent (or, at least, fileContent doesn’t point to a UITextView that gets displayed) when fileContentsViewController.filePath is set.

    You set filePath immediately after creating fileContentsViewController. If FileContentsViewController‘s -init doesn’t create an appropriate fileContent, then when -setFilePath: is called from -showFileContent, there’s no fileContent to set the text of. If fileContentsViewController is a typical view controller, fileContent won’t exist until fileContentsViewController is loaded, which (I believe) happens during -pushViewController:animated.

    One fix is to override -setFileContent to set fileContent.text as appropriate:

    -(void)setFileContent:(UITextView*)fileContentView {
        if (fileContent != fileContentView) {
            [fileContent release];
            fileContent = [fileContentView retain];
            if (self.filePath) { // if file path is not nil
                fileContent.text = ...;
            }
        }
    }
    

    Another other fix is to ensure you only set filePath when fileContent exists, but this is more brittle. A third is to set filePath after you push fileContentsViewController.

    The way you would discover the cause during debugging is to check two things: execution (“Is the code I’m expecting to be executed ever reached?”) and data (“Do the variables hold the values I expect?”). Set breakpoints in -showFileContent and -methodCall so you know that the methods are being called (which would be one reason for failure). If execution makes it into -methodCall, the problem must be something else. From there, examine the values of the variables used in -methodCall and you’ll discover fileContent is either nil or not the same fileContent that shows up later.

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

Sidebar

Related Questions

No related questions found

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.