PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, July 11, 2022

[FIXED] Why objective-c object does not refresh after receive a message?

 July 11, 2022     message, objective-c, refresh     No comments   

Issue

A have an NSView object, and it get an message after i push in the Menü bar the Open submenü. It load exchange data from a textfile, and it should render it in a CustomView. So the

-(IBAction)loadExchangeData:(id)sender 

load the data, and store in a NSMutableArray*, and after it should rendered it by drawRect.

But! In the drawRect function the before loaded data disappear, the NSMutableArray* will 0X0 again.

And part of the code:

.h:

 #import <Cocoa/Cocoa.h>
 @interface Chart : NSView 
 {
     NSMutableArray * exchange;
 }
 - (IBAction)loadExchangeData:(id)sender;
 @end

.m:

#import "Chart.h"
@implementation Chart
- (IBAction)loadExchangeData:(id)sender {
     ...
     exchange = [NSMutableArray array];
     [exchange addObject:...];
     ...
     return self;
}

- (void)drawRect:(NSRect)dirtyRect 
{
    ...
    id sth = [exchange objectAtIndex:i];
    ...
}
@end

Solution

by your explanation it looks like your referring different objects, your setting to NSMutableArray which is in one object and drarect is referring to a different object.

Debug the code to know the object address which hold the NSMutableArray, this could help you to narrow down the issue.

For further assistance add part of code to know more.

Update based on the code and comment

You might have a object in nib and one created in code, in this case avoid the creation of object in code and refer the object created in nib in code using outlet(IBOutlet).



Answered By - Girish Kolari
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing