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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:34:20+00:00 2026-06-15T05:34:20+00:00

I simply try to understand how to pass values from a textfield in AppDelegate

  • 0

I simply try to understand how to pass values from a textfield in AppDelegate to my NSView subclass “ViewController”. I really don’t get it. I’m new in objective-c and I start getting frustrated. Please just don’t tell me to read books. I have Hillegass COCOA programming and even there I didn’t find my answers. Call me rather idiot I can handle that as long I get that stuff…
I simply try to set the rectangle hight by the input variable balkenHoehe:

my AppDelegate .h:

#import <Cocoa/Cocoa.h>  
@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *eingabeText;

- (IBAction)pushButton:(NSButton *)sender;

@end

my AppDelegate .m:

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSLog(@"did launch");
}

- (IBAction)pushButton:(NSButton *)sender {

    NSLog(@"Button pushed");
    double number;

    number = [_eingabeText doubleValue]; //input by textfield

    CustomView *hoehe = [[CustomView alloc] init];
    [hoehe setBalkenHoehe:number];

}
@end

my CustomView .h:

#import <Cocoa/Cocoa.h>

@interface CustomView : NSView
{
   double balkenHoehe;
}

-(double) balkenHoehe;
-(void) setBalkenHoehe:(double)abalkenHoehe;
@end

my CustomView .m:

#import "CustomView.h"

@implementation CustomView

//********************************
-(void) setBalkenHoehe:(double)abalkenHoehe
{
    balkenHoehe = abalkenHoehe;
    [self setNeedsDisplay:YES];
}

//********************************
-(double)balkenHoehe
{
return balkenHoehe;

}

//********************************
- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {

    [self setBalkenHoehe:10]; //initial hight at start


    }
    return self;
}

//********************************
- (void)drawRect:(NSRect)rect
{
    NSRect bounds = [self bounds];
    float fieldWith = bounds.size.width / 3.0;
    float fieldHeight = bounds.size.height / 3.0;


        //background
    NSRect hintergrundRect =
    hintergrundRect = NSMakeRect(bounds.origin.x, bounds.origin.y,
                             bounds.size.width, bounds.size.height);
    [[NSColor grayColor] set];
    [NSBezierPath fillRect:hintergrundRect];

        //Diagram
    NSRect aRect =
    aRect = NSMakeRect (fieldWith, fieldHeight, fieldWith, balkenHoehe);

        // draw rectangle
    [[NSColor whiteColor] set];
    [NSBezierPath fillRect:aRect];

        // draw rect border
    [[NSColor blackColor] set];
    NSBezierPath *aPath = [NSBezierPath bezierPathWithRect:aRect];
    [aPath setLineWidth:1];
    [aPath stroke];

}

@end
  • 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-15T05:34:21+00:00Added an answer on June 15, 2026 at 5:34 am

    Horatiu is right, you’re not adding the hoehe NSView to the window, there is nowhere to display it. However, the suggestion he makes is for iOS, I think, while this seems to be OS/X. one way to add the view to the window is to write

    [self.window setContentView:hoehe];
    

    in pushButton:. However, this only works once, it then wipes out the view of the button!

    A more usable way is to add the hoehe view to the existing window’s contentView:

    ViewController *hoehe = [[ViewController alloc] init];
    [hoehe setFrame:CGRectMake(20, 20, 100, 100)]; // or whatever
    [self.window.contentView addSubview:hoehe ];
    [hoehe setBalkenHoehe:number];
    

    But be aware that each time you press the button, you create a new NSView and plant it on top of all those gone previously.

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

Sidebar

Related Questions

Im really new to Grails and I try to understand how it works. I
As hard as I try, PREG and I don't get along, so, I am
[Edit: don't try to understand the whole thing and don't waste your time to
I simply try to assign a background color to each div. it looks simple
I try to work with ctags and it simply doesn't work. I follow this
I'm going to try and explain this as simply as I can, it's most
I am attempting to understand the logic in the data.table from the documentation and
As with most, I come from and RDMS world trying to get my head
I'm trying to understand if it's possible to access a Google Drive from a
Françoise Lefèvre@example.com I'm reading RFC 5321 to try to actually understand what constitutes a

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.