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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:16:59+00:00 2026-06-06T02:16:59+00:00

I’m trying to figure out why my NSTextFields are only retained in the first

  • 0

I’m trying to figure out why my NSTextFields are only retained in the first method sendVarsToButton but not in the updateTotal method. I need to access the values from the TextField set in the first method but I can’t because it seems like my IBOutlets deallocate themselves after the sendVarsToButton method. Can you help me please!?

Here’s my .h

#import <Cocoa/Cocoa.h>
#import "TransactionViewController.h"
@class TransactionButtonModel;

@interface TransactionButtonController : TransactionViewController

{
NSMutableArray *buttonsArrays;
TransactionViewController *transactionViewController;
TransactionButtonModel *transactionButtonModel;
}
@property(nonatomic,retain) IBOutlet NSTextField *nom;
@property(nonatomic,retain) IBOutlet NSTextField *descriptionText;
@property(nonatomic,retain) IBOutlet NSTextField *prix;
@property(nonatomic,retain) IBOutlet NSTextField *CPUField;
@property(nonatomic,retain) IBOutlet NSTextField *quantite;
@property(nonatomic,retain) IBOutlet NSTextField *total;

-(void)sendVarsToButton:(NSString *)name:(NSString *)description:(double)price:(double)CPU:(long)tag;
-(void)updateTotal:(int)newQuantity;
-(void)addQuantiteToExistingProduct:(long)tag;
-(IBAction)removeProductFromView:(id)sender;

Here’s my .m

#import "TransactionButtonController.h"
#import "TransactionViewController.h"
#import "TransactionButtonModel.h"

@implementation TransactionButtonController
@synthesize prix;
@synthesize nom;
@synthesize descriptionText;
@synthesize CPUField;
@synthesize total;
@synthesize quantite;

//In this method, everything works fine

-(void)sendVarsToButton:(NSString *)name :(NSString *)description :(double)price :(double)CPU:(long)tag
{
[nom setTag:tag];
[descriptionText setTag:tag];
[prix setTag:tag];
[CPUField setTag:tag];
[quantite setTag:tag];
[total setTag:tag];

nom.stringValue = name;
descriptionText.stringValue = description;
[prix setDoubleValue : price];
CPUField.doubleValue = CPU;

total.doubleValue = [TransactionButtonModel calculateButtonTotal:quantite.intValue :prix.doubleValue];

NSLog(@"retain! :%lu",[[prix viewWithTag:tag] retainCount]); // returns 2

[transactionButtonModel release];

}
-(void)updateTotal:(int)newQuantity
{
NSLog(@"retain! :%lu",[[prix viewWithTag:2] retainCount]); //returns 0
[total setDoubleValue:[TransactionButtonModel calculateButtonTotal:newQuantity :prix.doubleValue]]; // value of prix = 0 and prix = null
NSLog(@"Updated! :%i",newQuantity);
}

-(void)dealloc
{
[nom release];
[quantite release];
[prix release];
[total release];
[descriptionText release];
}

Thanks in advance.

  • 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-06T02:17:02+00:00Added an answer on June 6, 2026 at 2:17 am

    It sounds like you have a few problems here. In no particular order:

    1. You’re releasing transactionButtonModel in sendVarsToButton::::: even though you didn’t create it there and there’s no particularly obvious reason you’d want to. This seems like probably a memory management error, but it’s hard to say without context.

    2. You’re looking to the reference counting mechanisms to see why a variable is null. Overreleasing an object does not set variables referencing that object to null — it would just be a junk pointer and probably crash your program. The most likely reasons for a variable to be unexpectedly null are a) methods running in a different order than you expect, or b) having two different instances of your class that you’re treating as though they’re the same one. My money would be on B in this case. You’re probably creating two instances of this class, one of which is actually showing the view and the other being essentially “blank.” Try logging self in the two methods and see if it’s the same object.

    3. In one method you’re logging viewWithTag:tag and in the other you’re logging viewWithTag:2 — it’s not necessarily a safe assumption that tag is 2.

    4. prix is an NSTextField — why are you asking it for subviews? NSTextField isn’t generally expected to have any useful subviews. There seems to be something odd in this design.

    5. Your method names are nuts with all those bare colons. It’s hard to read and often leads to mistakes down the line (due to the likelihood of misreading the code when you’re not “in the moment” and the fact that it violates the language’s idioms).

    6. You’re depending on retainCount to track memory management. The value returned by retainCount is questionable at best and often downright deceptive because things get retained and autoreleased all the time, and retainCount won’t give you enough information to account for that. If you have a memory management problem (which doesn’t appear to be this case with your variable becoming nil), a good approach would be to use Instruments and the debugger to track it down, not random retainCount logging.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like 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.