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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:49:51+00:00 2026-05-25T20:49:51+00:00

I have a Cocoa app for Mac OS X written in Xcode 4. The

  • 0

I have a Cocoa app for Mac OS X written in Xcode 4. The app has a main window that is the app delegate. This window has a button that opens another window (call it pop window) with 2 TextFields and a couple of buttons. When the user click one of those button the idea is to close the pop window and grab the text from the 1st TextField and use it on the app delegate.

The code I have is as follow.

App delegate .h:

@interface TestAppAppDelegate : NSObject <NSApplicationDelegate> {
NSString *valueofedit;
@private
    NSWindow *window;
    NSPersistentStoreCoordinator *__persistentStoreCoordinator;
    NSManagedObjectModel *__managedObjectModel;
    NSManagedObjectContext *__managedObjectContext;
    NSTextField *_StatusLabel;
}

@property (assign) IBOutlet NSWindow *window;
@property (nonatomic, retain) NSString *valueofedit;
@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel;
@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
@property (assign) IBOutlet NSTextField *StatusLabel;

- (IBAction)GetStatClick:(id)sender;
- (IBAction)OnLaunch:(id)sender;
- (IBAction)saveAction:sender;

@end

The Delegate .m:

#import "TestAppAppDelegate.h"
#import "MyClass.h"

@implementation TestAppAppDelegate
@synthesize StatusLabel = _StatusLabel;
@synthesize valueofedit;
@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    valueofedit = [[[NSString alloc] init] autorelease];
}


- (IBAction)GetStatClick:(id)sender {

// I need to get the value of the pop window textfield here.
}


- (IBAction)OnLaunch:(id)sender {

    MyClass *controllerWindow = [[MyClass alloc] initWithWindowNibName:@"pop"]; 
    [controllerWindow showWindow:self];

    // this of course is always null    
    NSString * tmp = [controllerWindow valueofedit];
    NSLog(@"result: %@", tmp);

}

@end

OnLaunch will pop the new window.

The the pop window code

The .h:

@interface MyClass : NSWindowController {
NSString *valueofedit;
@public

    NSTextField *one;
    NSTextField *two;    
    NSWindow *popupwin;
}
@property (assign) IBOutlet NSWindow *popupwin;

@property (assign) IBOutlet NSTextField *one;
@property (assign) IBOutlet NSTextField *two;
@property (nonatomic, retain) NSString *valueofedit;

- (IBAction)onclose:(id)sender;

@end

and the .m

#import "MyClass.h"
#import "TestAppAppDelegate.h" //try to access the delegate but no luck

@implementation MyClass
@synthesize popupwin;
@synthesize one;
@synthesize two;
@synthesize valueofedit;

// when we hit the "Done" button
- (IBAction)onclose:(id)sender 
{    
    // the value of the textfield that I need
    valueofedit = [one stringValue];

    // I tried to get the value sent to the app delegate
    TestAppAppDelegate *mainwin = [TestAppAppDelegate alloc];

    [[mainwin valueofedit] initWithFormat:@"%@", valueofedit];
    [popupwin close];    
}
@end

So the idea was that since I can’t access the pop window directly I tried with having a variable made public on the app delegate and copy the value of the text field there before closing the pop window. It didn’t work.

How do I do this? How do i pass the value of the text field of one window to another?

Note: No, I can’t use alerts for this.

Code samples are appreciated. Thank you.

  • 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-25T20:49:51+00:00Added an answer on May 25, 2026 at 8:49 pm

    You are allocating a new instance of your application delegate. Instead of [TestApplicationDelegate alloc] you should be using [NSApp delegate].

    Once you have a pointer to the actual delegate, you are not using the accessor properly to set the vauleOfEdit property.

    Currently you are calling initwithformat on the returned value of an accessor, which is either going to be nil or an already initialised string.

    Amend your onclose method to:

    // when we hit the "Done" button
    - (IBAction)onclose:(id)sender 
    {    
        TestAppAppDelegate *mainwin = (TestAppAppDelegate*)[NSApp delegate];
    
        mainwin.valueofedit = [one stringValue];
        [popupwin close];    
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple Mac Cocoa app that just has a Web View
I have come across this Cocoa application (source code) that shows a main Window.
I have a graphics editing cocoa app on Mac OSX that produces 32 by
I have a Cocoa app I'm writing that has an ImageView with a TextView
I am using Xcode to create an Objective-C, cocoa, mac app. I have a
I am using Xcode to create a Cocoa app for Mac OSX written in
I am using Xcode to create a Mac OSX, Objective-C, cocoa app. I have
I have a multi-threaded Cocoa app that processes images. The program has a progress
I have a Cocoa app that uses a WebView to display an HTML interface.
I'm writing a Cocoa application where I have an auto generated app delegate:(MyAppDelegate.h/MyAppDelegate.m) So

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.