Re: Strange NSZombie occurring
> Have you seen Hillegass's book on Cocoa. It's an excellent start for Cocoa > newbies. I took Aaron's course about 10 years ago, but didn't have a chance to use Cocoa since then due to job requirements. I lost a lot of my books recently in a disaster (aren't you all getting tired of knowing how crappy my life is?). My wife insisted on avoiding dead tree books since then, so I only have it in eBook form, but it's too difficult to search. I intend to read both Aaron's and Matt Neuberg's iOS books when I'm ready to try an iPad app. >> Yes, I know this is a kludge... > > I'm not so sure about that; sounds reasonable to me. Thanks. That feedback is reassuring. Scott Sent from my iPad ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Strange NSZombie occurring
Ah. I see some of your points. Very dumb of me. I'm new to Cocoa, but I did program in a number of other languages for 30 years. I apologize for not being clear enough. Pain and nausea tend to mess up the clarity of my thinking. Unfortunately, I'm ill most of the time (don't ask about my health. It's too depressing). This also makes it take an extremely long time to get any program done. In the past, I got into the habit of not asking for help, and forcing myself to figure out the solution on my own. I don't like to bother other people with my problems (besides, learning from my mistakes was the way I learned before). Maybe with Cocoa this is a bad idea. >> Is this your exact code? You use wordsFromPhrase: here but the method below >> is wordsInPhrase:. This is a typo. The same method names are used in my code. I tried to pare down the source code to a manageable length for posting my question. When I looked at it afterwards, I didn't notice my own typos. I always the a long time to check for such typos when within Xcode. To give you a little more background about the context of the code snippets in the full program, I'm trying to animate the individual words of the phrase in sequence with fading in and out, color changes, etc. I'm using Core Animation in conjunction with the NSTimer because I could not find an elegant way to create an NSKeyframeAnimation in which each individual word of my phrase (displayed in a CATextLayer) could be swapped in sync with the other animatable properties. Each individual word had to be set before the animation started. My solution was to use the timer's changeWords: method to change the words and trigger a one-shot animation on each invocation, with the timer's duration slightly longer than the animation's duration. Yes, I know this is a kludge, but it was the only way that I could come up with to solve this problem. I ran it past a few other people and they thought it would work. Any other approaches would be appreciated. > Another thing: you are ignoring the argument thePhrase. Right. In paring down the code for my post, I passed an argument. In my working code, I simply use the phrase property within the method. Sorry about making that mistake and confusing the issue. And, yes, I am declaring ivars for all of the properties. > phrase = @"This is the phrase to display";// stringWithString: is almost > never what you intend. God, was that stupid! Of course I should have done that! > Do you ever want to change .words without doing [self start]? If not, make > the call to -start inside setWords:. Then self.words = [self wordsFromPhrase: > self.phrase] can completely replace -setUp. Good point. Within start: I call different methods for each type of animation to use, but I never change the words without calling [self start]. This would be a good place to move that call. I had not refactored my code yet. > NSArray *wordArray; > [wordArray arrayByAddingObjectsFromArray:[phrase > componentsSeparatedByString:@" "]]; I did not notice that mistake. That _should_ crash. Thanks. > and that you _really_ mean: > @property(nonatomic, readonly) NSUInteger numWords; > @property(nonatomic, readonly) NSArray *words; > @property(nonatomic, retain) NSArray * backingWordsArray; I thought that properties such as NSString and NSArray needed to be retained or copied. Am I wrong? > wordChangeTimer = [[NSTimer scheduledTimerWithTimeInterval:wordChangeInterval > [My customary objection to accessing an ivar directly.] I tried both wordChangeTimer and self.wordChangeTimer when I was testing the program. Both worked, so I left it as is. > self.wordChangeTimer = [NSTimer ... repeats: YES]; > If you let the property manage your memory, you won't have to do it yourself. > And if you have a setter method, you can invalidate the old timer. Would invalidating within the setter as the NSTimer is assign in the code above for the first time cause a problem? > What are setUpDisplay and startDisplay? Are they the same as setUp and start? Yeah. Another typo. You know, when I took a mandatory typing class in junior high school, I was the worst typist in the class. That's probably why I was also a terrible piano player. I ran everything through the debugger, and stepped though it. That's how I knew that words had a non-nil value in start and not have it in changeWords:. As for Instruments, I find Apple's documentation very unclear. I've only used Instruments on one project before this, and managed to remove a leak. When I ran Instruments on this project, I did not notice a leak. However, since I'm so new to Instruments, it's entirely possible that I forgot how to use it properly again on this project. ;-) Is there a good tutorial on using Instruments? All I've seen on-line are descriptions of the tools within Instruments, but not clear instructions on how to use them. I will take your advice and correct my
Strange NSZombie occurring
I've got a zombie appearing in the weirdest place in my program. Here is the relevant part of the code, using generic names for the methods: -(void)setUp; -(void)start; -(void)changeWords:(NSTimer*)theTimer; -(NSArray *)wordsInPhrase:(NSString *)thePhrase; @property (nonatomic, assign) int numWords; @property (nonatomic, assign) NSUInt wordChangeInterval; @property (nonatomic, copy) NSString *phrase; @property (nonatomic, copy) NSArray *words; @property (nonatomic, copy) NSTimer *wordChangeTimer; … - (id)init { self = [super init]; if (self) { phrase = [[NSString stringWithString:@"This is the phrase to display"] retain]; wordChangeInterval = 0.2; } return self; } -(void)setUp { words = [[self wordsFromPhrase:phrase]] retain]; [self start]; } -(NSArray *)wordsInPhrase:(NSString *)thePhrase { NSArray *wordArray; [wordArray arrayByAddingObjectsFromArray:[phrase componentsSeparatedByString:@" "]]; numWords = [wordArray count]; return wordArray; } - (void) start { currentWordIndex = 0; wordChangeTimer = [[NSTimer scheduledTimerWithTimeInterval:wordChangeInterval target:self selector:@selector(changeWords:) userInfo:nil repeats:YES] retain]; } - (void)changeWords:(NSTimer*)theTimer { currentWordIndex += 1; if (currentWordIndex > numWords) currentWordIndex = 0; messageLayer.string = [self.words objectAtIndex:currentWordIndex]; } Now, the strangeness: words exists and is OK in setUpDisplay and startDisplay in that it contains the right words from the phrase. But in changeWords:, somehow words is nil. I'm at a loss to figure out how words could be released between start and changeWords:. I'd appreciate some help. Thanks. Scott Dr. Scott Steinman Brought to you by a grant from the Steinman Foundation (Thanks, Mom and Dad!) Recommended by Major University Studies Over the Leading Brand drsteinman at comcast dot net I hope I die peacefully in my sleep like my grandfather. . .not screaming in terror like his passengers. -- "Deep Thoughts", Jack Handy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Ticker tape display
I have drawn text into a CALayer. I'd like to allow the user select the type of animation effect displayed, such as fading the text in/out by changing the CALayer's opacity. One of the effects I'm trying to do is a ticker tape display where a line of text is scrolled repeatedly from off-screen on the right side to off-screen on the left side. What would be a good approach for this? 1. Use a CALayer whose width is that of its containing NSView, with its position animated from off-screen on the right, across the screen, then off-screen to the left? I can't find any documentation that would suggest that a CALayer's starting position can be off-screen past the edges of its containing NSView (with the contents of the CALayer clipped to the edges of the NSView). 2. Make the containing NSView's width three times the width of the screen (so the CALayer has enough room to be off the screen to the left and to the right)? That would be very expensive memory-wise, so I'm hesitant to do it. 3. Use a CALayer that is scrolled by translating in 3D space, or would this preclude using other animation effects, such as fading the text in and out by changing transparency? I hope I've made myself clear enough. All I'm asking for is advice for a starting point to use. I'll do the research and coding after that so I can learn Core Animation. Thanks in advance for your help. Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Animating a flickering display
Thanks for the help. I don't know Quartz Composer yet, but I'll take a look at the documentation and see if it fits my needs for the current program. I've been mulling it over, and may create a git branch to try Core Animation. First, it may facilitate future alternative animated displays such as scrolling test. Second, I might as well have some fun and learn it! Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Animating a flickering display
The purpose of the program is to compare the visibility of the text when it is static versus when it flickers (so in some ways it's similar to signage). Therefore, I must make the text display switch back and forth between two displays with opposite black/white contrast to produce the flicker -- either a sudden swap or easing in/out are acceptable, as long as the switching back and forth can be repeated indefinitely at a given rate and does not block other GUI actions (a button press will be used to stop the animation). The smoothness of the font via anti-aliasing is not that important. I hope that this is enough information to make the task more understandable. Scott On Jul 4, 2011, at 2:30 PM, Kyle Sluder wrote: > On Mon, Jul 4, 2011 at 11:31 AM, Dr. Scott Steinman wrote: >> My program needs to display counterphase flickering test, i.e., one display >> is white text on a black background, and the other is black text on a white >> background, and the two displays are switched back and forth. I have >> concluded that there are two options to do this: > > It might help to explain what you're doing in more detail. Is this for > signage, or for testing video monitors, or what? Do you want the > animation to ease in/out, or abruptly swap periodically? Is the text > dynamic? Do you care about subpixel anti-aliasing? > > --Kyle Sluder Scott Steinman, O.D., Ph.D. Sent from my iPad ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Animating a flickering display
My program needs to display counterphase flickering test, i.e., one display is white text on a black background, and the other is black text on a white background, and the two displays are switched back and forth. I have concluded that there are two options to do this: 1. Draw each display into two NSViews, then switch back and forth between between them (via replaceSubview:with:) with an NSTimer to time the switches. 2. Use Core Animation to fade in one display and fade in the other. In each case, I don't know how to avoid blocking a button presses whose action would stop the animation. Which is the better way to proceed? How do I keep the user interface responsive? Please point me in the right direction. Thank you. Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Printing graphics plus text
Please forgive me if my question is stupid. It's frustrating being a Cocoa noobie after 30 years of scientific programming, but I'm doing my best to learn. I'm working on an application that displays a diagram I have drawn in a custom view to represent data input by the user. I'd like to print that diagram plus the input values. I've read explanations and examples in Apple's documentation, my library of Cocoa books, and from web searches. Each explains only how to print either a view graphics or a view containing text by instantiating an offscreen instance of that single view and redrawing its contents for printing. Unfortunately, none of them shows how to print two views containing different contents. Can the offscreen view contain subviews that each know how to draw themselves? Thank you in advance for your help. Unless I run into a problem, I won't respond here so I don't decrease the signal to noise ratio of this list. Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: drawRect: GCContext errors
Problem solved! Thanks to Matt Neuberg for his suggestion. It let me hone in on the culprit. Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
drawRect: GCContext errors
I've been sitting at home sick for over a month, trying to keep sane by re-learning Cocoa. I am just about to complete my first non-trivial Cocoa application. The application is working perfectly, including no memory management issues, but I've been constantly checking the console so I can make sure I don't miss any subtle problems. Unfortunately, I'm getting strange error messages in the console when the application's main window first opens. The window contains, among standard controls, two custom NSViews: 1. An x-y plot of data. 2. A drawing of a color-filled circle created in the custom view's drawRect: method. All that's used are the standard NSColor and NSBezierPath classes. Pretty trivial stuff. Two copies of these views are used in the window as a figure legends for the plot. In the window's awakeFromNib: method, the model class is created and initialized, then the two legend custom views are assigned their colors. When the figure legends' drawRect: method is executed, the console spits out about 50 or so Core Graphics errors stating that there's an invalid CGContext for anything from setting line width to setting a line join, and so on -- I assume all of this stuff is going on in the background since I'm not doing any direct Core Graphics calls. The errors are triggered by each of the following lines of code: 1. Erasing the background with NSRectFill( [self bounds] ). 2. Setting the color using [[NSColor blackColor] set]. 3. Drawing the circle outline with [[NSBezierPath bezierPathWithOvalInRect: theLegendFrame] stroke], where theLegendFrame is a local copy of the view's bounds. 4. Setting the color with [[self legendColor] set];, where the legendColor is the color assigned as mentioned above. 5. Filling the circle (after the framing NSRect is inset) with [[NSBezierPath bezierPathWithOvalInRect: theLegendFrame] fill]; Surprisingly, there are no such errors in my plot drawing code, and it's a lot more complicated! I am completely puzzled by these errors because I thought that using simple Cocoa drawing classes solely within drawRect: meant that CGContents would not have to be set manually (at least that's what code examples in my books and on the web say). I've been scouring the Apple documentation, mailing lists, web sites -- anything that could give a clue before asking a potentially stupid newbie question. I know that I'm having difficulty concentrating, so forgive me if I'm coming across like a complete idiot or missing a blatantly obvious fact. Could you please point me to where I can start to look for a solution to these CGContext problems? Thank you. Scott ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Sharing a model
Thank you for the replies so far. I had not designed my program as a document-based application because I did not think that I would save and open data files. However, I have changed my viewpoint. It might also make implementing your suggestions easier. -Scott Steinman ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Sharing a model
Please forgive me since I'm a Cocoa newbie (having programmed in about a dozen programming languages on many computer architectures -- this hints at my age!), but I can't find an answer to what I think should be a simple question via the Apple documentation, multiple Cocoa books, or web search engines. I'm working on an application that takes medical test data and outputs diagnostic data. My application's window contains several controls and labels to enter numeric data and display the results of the calculations. It also contains a custom NSView that will present a graphical representation of the data. At present, the model and the window are interconnected by one controller. The model object is instantiated in the awakeFromNib: method of the controller. However, the controller class will get huge when the graphics code is added. I'd like to split up the controller class into more manageable parts. I'm hoping to have one controller for the graphics NSView alone and another for everything else in the window. Both controllers would need access to the same model. What is the best way to accomplish this? 1. Where should I instantiate and later dealloc the model object? 2. How do I get both controllers to reference this single model without creating coupling between the controllers? 3. When should the reference to the model be set up in each controller? Thanks in advance for your help. Scott Steinman ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com