Re: [iPhone 3.0] correct way to release a UIImageView flip animation?
Kyle et al, No problem -- here's my code. There is obviously something i'm not getting, so any help is truly appreciated. First, my view controller has a showAnimation method that is called to play the currently loaded animation: - (void)showAnimation { // only play the animation if the preloader thread has finished ... lilappAppDelegate *delegate = (lilappAppDelegate *) [[UIApplication sharedApplication] delegate]; [delegate stopAnimations]; if(YES == delegate.animationPreloaded) { delegate.animationView.animationImages = delegate.animationArray; [delegate playAnimation:self.view]; [delegate preloadNextAnimation]; } } ... and I run a thread to preload the next animation (this code always preloads the same one, but the idea is that they'll change, and I don't want to load them all at once and waste memory): - (void)preloadAnimationThread { NSAutoreleasePool *outerPool = [[NSAutoreleasePool alloc] init]; self.animationPreloaded = NO; int frameIndex = 0; [NSThread sleepForTimeInterval:5]; [self performSelectorOnMainThread:@selector(releaseAnimations) withObject:nil waitUntilDone:YES]; [self.animationArray release]; self.animationArray = [[NSMutableArray alloc] init]; for (frameIndex = 0; frameIndex 47; frameIndex += 2) { NSString *frameName = [NSString stringWithFormat:@clapping_ %05i.png, frameIndex]; // I tried [UIImage imageContentsFromFile], but it resulted in animations that played on the sim but // not on the device ... [self.animationArray addObject:[UIImage imageNamed:frameName]]; } self.animationPreloaded = YES; [outerPool release]; } - (void)releaseAnimations { self.animationView.animationImages = nil; } - (void)stopAnimations { [self.animationView stopAnimating]; } On Aug 8, 2009, at 10:24 PM, Kyle Sluder wrote: On Aug 8, 2009, at 8:14 PM, John Michael Zorko jmzo...@mac.com wrote: My question -- what is the correct way to release the UIImageView's animatedImages array? I assign an NSMutableArray to it, play the animation, then set the UIImageView's animatedImages to nil. I then release the NSMutableArray and recreate it. Is this correct? Your question is meaningless without context, and the fact that you're asking it indicates a lack of familiarity with the Cocoa memory management rules. Since we have been asked not to paraphrase them here, all I can suggest is that you review the documentation and, if you're still confused, post your code. --Kyle Sluder Regards, John Falling You - exploring the beauty of voice and sound http://www.fallingyou.com ___ 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: [iPhone 3.0] correct way to release a UIImageView flip animation?
Kyle et al, BTW, the issue I see is the infamous program exited with signal:0 error, with no backtrace. On Aug 8, 2009, at 10:24 PM, Kyle Sluder wrote: On Aug 8, 2009, at 8:14 PM, John Michael Zorko jmzo...@mac.com wrote: My question -- what is the correct way to release the UIImageView's animatedImages array? I assign an NSMutableArray to it, play the animation, then set the UIImageView's animatedImages to nil. I then release the NSMutableArray and recreate it. Is this correct? Your question is meaningless without context, and the fact that you're asking it indicates a lack of familiarity with the Cocoa memory management rules. Since we have been asked not to paraphrase them here, all I can suggest is that you review the documentation and, if you're still confused, post your code. --Kyle Sluder Regards, John Falling You - exploring the beauty of voice and sound http://www.fallingyou.com ___ 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: [iPhone 3.0] correct way to release a UIImageView flip animation?
Kyle et al, Wow, it's late ... I forgot some of the code in the last email -- here's all of it (still not much, no worries). I see the program exited with signal:0 error after this code runs for awhile, and there's no backtrace. On my view controller is: - (void)showAnimation { // only play the animation if the preloader thread has finished ... lilappAppDelegate *delegate = (lilappAppDelegate *)[[UIApplication sharedApplication] delegate]; [delegate stopAnimations]; if(YES == delegate.animationPreloaded) { delegate.animationView.animationImages = delegate.animationArray; [delegate playAnimation:self.view]; [delegate preloadNextAnimation]; } } ... and I run a thread to preload the next animation (this code always preloads the same one, but the idea is that they'll change, and I don't want to load them all at once and waste memory): On my app delegate are: - (void)preloadAnimationThread { NSAutoreleasePool *outerPool = [[NSAutoreleasePool alloc] init]; self.animationPreloaded = NO; int frameIndex = 0; [NSThread sleepForTimeInterval:5]; [self performSelectorOnMainThread:@selector(releaseAnimations) withObject:nil waitUntilDone:YES]; [self.animationArray release]; self.animationArray = [[NSMutableArray alloc] init]; for (frameIndex = 0; frameIndex 47; frameIndex += 2) { NSString *frameName = [NSString stringWithFormat:@clapping_ %05i.png, frameIndex]; // I tried [UIImage imageContentsFromFile], but it resulted in animations that played on the sim but // not on the device ... [self.animationArray addObject:[UIImage imageNamed:frameName]]; } self.animationPreloaded = YES; [outerPool release]; } - (void)playAnimation:(UIView *)view { [self.animationView setAnimationDuration: [self.animationView.animationImages count] / 12]; self.animationView.animationRepeatCount = 1; [view addSubview:self.animationView]; [self.animationView startAnimating]; } - (void)preloadNextAnimation { self.animationPreloaded = NO; // now preload the next ones ... [self performSelectorInBackground:@selector(preloadAnimationThread) withObject:nil]; } - (void)releaseAnimations { self.animationView.animationImages = nil; } - (void)stopAnimations { [self.animationView stopAnimating]; } On Aug 8, 2009, at 10:24 PM, Kyle Sluder wrote: On Aug 8, 2009, at 8:14 PM, John Michael Zorko jmzo...@mac.com wrote: My question -- what is the correct way to release the UIImageView's animatedImages array? I assign an NSMutableArray to it, play the animation, then set the UIImageView's animatedImages to nil. I then release the NSMutableArray and recreate it. Is this correct? Your question is meaningless without context, and the fact that you're asking it indicates a lack of familiarity with the Cocoa memory management rules. Since we have been asked not to paraphrase them here, all I can suggest is that you review the documentation and, if you're still confused, post your code. --Kyle Sluder Regards, John Falling You - exploring the beauty of voice and sound http://www.fallingyou.com ___ 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
Core Data - attribute to hold an array of strings
I created an Entity called MyPlaces. I want to store a number of strings inside MyPlaces. How do I create an attribute to hold an array of strings? I know how to create an Attribute to hold a single string but I need to hold an array of strings. One way is to create another Entity called PlaceName. PlaceName will have an attribute of type String. I will then make a to-many relationship from MyPlaces to PlaceName. But this seems way too roundabout to solve my problem. Is there an easier way? Thanks Hrishi ___ 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: Core Data - attribute to hold an array of strings
Create an attribute of type Binary Data. Encode your anArray of strings into an NSData using something like NSData *arrayData = [NSArchiver archivedDataWithRootObject:anArray];. Finally, put arrayData into the attribute. Shlok Datye Coding Turtle http://codingturtle.com On 09.08.2009, at 09:48, M.S. Hrishikesh wrote: I created an Entity called MyPlaces. I want to store a number of strings inside MyPlaces. How do I create an attribute to hold an array of strings? I know how to create an Attribute to hold a single string but I need to hold an array of strings. One way is to create another Entity called PlaceName. PlaceName will have an attribute of type String. I will then make a to-many relationship from MyPlaces to PlaceName. But this seems way too roundabout to solve my problem. Is there an easier way? Thanks Hrishi ___ 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: Core Data - attribute to hold an array of strings
Look for these classes in the documentation. If they conform to the NSCoding protocol they can be archived. If they don’t, they can’t, and you might be able to find something useful by googling for SomeClass NSCoding. Shlok Datye Coding Turtle http://codingturtle.com On 09.08.2009, at 10:25, M.S. Hrishikesh wrote: Can I use the same method for UIImage or NSImage also? On 09/08/09 3:48 PM, Shlok Datye wrote: Create an attribute of type Binary Data. Encode your anArray of strings into an NSData using something like NSData *arrayData = [NSArchiver archivedDataWithRootObject:anArray];. Finally, put arrayData into the attribute. Shlok Datye Coding Turtle http://codingturtle.com On 09.08.2009, at 09:48, M.S. Hrishikesh wrote: I created an Entity called MyPlaces. I want to store a number of strings inside MyPlaces. How do I create an attribute to hold an array of strings? I know how to create an Attribute to hold a single string but I need to hold an array of strings. One way is to create another Entity called PlaceName. PlaceName will have an attribute of type String. I will then make a to-many relationship from MyPlaces to PlaceName. But this seems way too roundabout to solve my problem. Is there an easier way? Thanks Hrishi ___ 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: Core Data - attribute to hold an array of strings
Yes, you can. Only thing is you need to convert UIImage object to NSData object. There are two C APIs - UIImageJPEGRepresentationhttp://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageJPEGRepresentation - UIImagePNGRepresentationhttp://developer.apple.com/iPhone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImagePNGRepresentation which you can use to get NSData object of UIImage object. As you know, NSData in compliant to NSCoding protocol, you can achieve your objective. Hope this helps. ~Parag On Sun, Aug 9, 2009 at 4:31 PM, Shlok Datye li...@codingturtle.com wrote: Look for these classes in the documentation. If they conform to the NSCoding protocol they can be archived. If they don�t, they can�t, and you might be able to find something useful by googling for SomeClass NSCoding. Shlok Datye Coding Turtle http://codingturtle.com On 09.08.2009, at 10:25, M.S. Hrishikesh wrote: Can I use the same method for UIImage or NSImage also? On 09/08/09 3:48 PM, Shlok Datye wrote: Create an attribute of type Binary Data. Encode your anArray of strings into an NSData using something like NSData *arrayData = [NSArchiver archivedDataWithRootObject:anArray];. Finally, put arrayData into the attribute. Shlok Datye Coding Turtle http://codingturtle.com On 09.08.2009, at 09:48, M.S. Hrishikesh wrote: I created an Entity called MyPlaces. I want to store a number of strings inside MyPlaces. How do I create an attribute to hold an array of strings? I know how to create an Attribute to hold a single string but I need to hold an array of strings. One way is to create another Entity called PlaceName. PlaceName will have an attribute of type String. I will then make a to-many relationship from MyPlaces to PlaceName. But this seems way too roundabout to solve my problem. Is there an easier way? Thanks Hrishi ___ 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/parag.vibhute%40gmail.com This email sent to parag.vibh...@gmail.com -- There are many things in your life that will catch your eye but only a few will catch your heartpursue those'. ___ 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
NSTimer not firing
Hi I'm running an NSInvocationOperation in an NSOperationQueue and set up a listener for the operation's isFinished notification. My observeValueForKeyPath method is getting called when the operation finishes, but I'm finding that when I try to create a timer inside observeValueForKeyPath, it never fires. I double checked the seconds input to [NSTimer scheduledTimerWithTimeInterval method and it's on;y 5 seconds so it's not like I'm inadvertently using a really long interval. It just never fires. When I use sleep(seconds) it does work, sort of, but have found that in a real environment, it often seems to crash with a bad kernel access error right at the sleep function. Anyone know why my timer might not be firing? Thanks for any help ___ 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: NSTimer not firing
On 9 Aug 2009, at 16:56, kentoz...@comcast.net wrote: I'm running an NSInvocationOperation in an NSOperationQueue and set up a listener for the operation's isFinished notification. My observeValueForKeyPath method is getting called when the operation finishes, but I'm finding that when I try to create a timer inside observeValueForKeyPath, it never fires. I double checked the seconds input to [NSTimer scheduledTimerWithTimeInterval method and it's on;y 5 seconds so it's not like I'm inadvertently using a really long interval. It just never fires. From the docs for NSOperation: Because an operation may execute in any thread, any KVO notifications associated with that operation may similarly occur in any thread. I think the problem, therefore, is that you're trying to schedule your timer on the wrong thread (I guess you're expecting it to be scheduled on your app's main thread)? Kind regards, Alastair. -- http://alastairs-place.net ___ 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: [iPhone 3.0] correct way to release a UIImageView flip animation?
On Aug 9, 2009, at 1:31 AM, John Michael Zorko wrote: Wow, it's late ... I forgot some of the code in the last email -- here's all of it (still not much, no worries). I see the program exited with signal:0 error after this code runs for awhile, and there's no backtrace. ... and I run a thread to preload the next animation (this code always preloads the same one, but the idea is that they'll change, and I don't want to load them all at once and waste memory): First, program exited with signal:0 suggests the app was killed by springboard instead of crashed on it's own. Check the device console log in the Organizer window and see if it was terminated for a specific reason. I'm going to guess you used too much memory too quickly. You have maybe 10 MB of RAM at your disposal on a good day (on a non-3GS device). Realistically, if you go over 7 MB too quickly (before springboard can ask other processes to terminate) your process will be terminated. Second, UIKit generally isn't thread safe and UIImage is a part of UIKit. You probably can't safely use it from a secondary thread. Dave ___ 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: NSTimer not firing
On 2009 Aug 09, at 09:26, Alastair Houghton wrote: I think the problem, therefore, is that you're trying to schedule your timer on the wrong thread (I guess you're expecting it to be scheduled on your app's main thread)? The performSelectorOnMainThread::: methods are your friend in situations like this. A cool thing I realized about these a few months ago is that they are also NSOperation's friend, because you can use them methods even if you ^are already^ on the main thread. Invocations are even better, since you can get return values, and non- object return values. But since I always forget how to make one, I've written a little category on NSInvocation that makes it easy for me. I use these liberally + (NSInvocation*)invocationWithTarget:(id)target selector:(SEL)selector retainArguments:(BOOL)retainArguments argumentAddresses: (void*)firstArgumentAddress, ... ; - (void)invokeOnMainThreadWaitUntilDone:(BOOL)waitUntilDone ; + (NSInvocation*)invokeOnMainThreadTarget:(id)target selector:(SEL)selector retainArguments:(BOOL)retainArguments waitUntilDone:(BOOL)waitUntilDone argumentAddresses: (void*)firstArgumentAddress, ... ; The trick is not to get deadlocks -- more than one operation waiting on the main thread. The way to avoid that is to step back and make a disciplined plan about what happens on what thread when. ___ 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
Color with pattern image
Hi, I'm using -[NSColor colorWithPatternImage:] to draw a background pattern image and I want to set a constraint for the drawing starting rectangle. The docs says that The image is tiled starting at the bottom of the window I've tried to vertically flip the drawing context but the pattern is always drawn upside-down from the bottom-left corner. CGContextScaleCTM(cgContext, 1.0f, -1.0f); CGContextTranslateCTM(cgContext, 0, -toRect.size.height); Is there any way to change this behaviour? Thank you. -- Ciao, Mirko ___ 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: Core Data - attribute to hold an array of strings
On Aug 9, 2009, at 4:39 AM, parag vibhute parag.vibh...@gmail.com wrote: Yes, you can. Only thing is you need to convert UIImage object to NSData object. There are two C APIs Good to know for the iPhone crowd, but the question was about NSImage, which is a Mac class. --Kyle Sluder ___ 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: Color with pattern image
On 10/08/2009, at 8:18 AM, Mirko Viviani wrote: I'm using -[NSColor colorWithPatternImage:] to draw a background pattern image and I want to set a constraint for the drawing starting rectangle. The docs says that The image is tiled starting at the bottom of the window ... Is there any way to change this behaviour? Yes, you can use the -setPatternPhase: method of NSGraphicsContext to draw the pattern in the location you expect. You have to calculate the offset yourself. Have a look at Dave Batton's excellent DBBackgroundView for an example: http://www.mere-mortal-software.com/blog/details.php?d=2007-01-16 -- Rob Keniger ___ 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: [iPhone 3.0; XCode 3.1.3] Question about when views are available for manipulation.
On Sat, Aug 8, 2009 at 10:40 PM, Brian Bruinewoudbr...@darknova.com wrote: as it could be? What would be the better way to achieve this? At a guess to my second question: I suppose the new view should call on methods/properties of its File's Owner to discover what it needs to display. I haven't tried this so I don't know if its a workable solution, but it seems like it could be. Earlier, you said: For example, if myProperty has a non-synthesized setter that expects IBOutlets to be bound it will be disappointed as they'll still be nil at this point. The idea that a data property setter should be manipulating view objects is what's getting you into trouble, IMHO. One way or another, your model data should be more separate from your view (see MVC). Otherwise, it's fine to set your own properties of your new controller MyController after you init it. Depending on whether your data is going to get modified by the user working in this view, you might give references or copies of your data objects to MyController, and let MyController's -viewDidLoad (after calling super) then set the contents of your views (probably interpreting/formatting at the same time). Your idea about calling File's Owner to get data is another way to go, except File's Owner is MyController, so that's not going to get you back to your object (containing the initWithNibName code you posted) that presumably has the data. If you think this is a good way to go for your app, you could give MyController a reference to that other object to ask it for the data. Your probably want to NOT retain that reference in MyController to avoid a reference loop, although you need to make sure that object doesn't go away before MyController does. As you see, this probably gives you more things to worry about than in the previous strategy. ___ 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
CATransition + NSView mask
I have a simple view transition, and am using a slide transition in combination with NSView's replaceSubview: with: method to swap a view's subviews. The problem I'm running into with this transition in particular is that it doesn't clip to the parent view. The views that are being swapped in are only clipping at the bounds of the window and not the view and the animation looks bad because there are other buttons, and textfields that are getting covered, etc. I see that CALayer has the maskToBounds attribute that clips the content of the layer. I can't find anything analogous for an NSView or anything associated with the animator proxy that fits. Anyone else run in to this problem? -- Evan ___ 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
Trouble with event taps...
Hi all, I'm having some difficulty with event taps. I am creating my event tap from the 'awakeFromNib' function for my overloaded NSWindow. The problem is that keyUp and keyDown events are never trapped in my callback. I can see all the mouse events, and even the modifier keys (shift, option, command, etc) are trapped fine. My callback function just logs stuff to the console and returns the event. My little debug prints also show that no bits in the eventMask are cleared away. Also, I do have 'Enable Assistive Devices' checked (or else I wouldn't even get the mouse events I'd imagine), so I don't think thats the problem. I have posted my event tap creation code below - I've searched all over the mailing list and the net to see if I could find a solution, but I am genuinely stuck. Any help is greatly appreciated! // Create an event tap. eventMask = CGEventMaskBit(kCGEventRightMouseDown) | CGEventMaskBit(kCGEventRightMouseUp) | CGEventMaskBit(kCGEventRightMouseDragged) | CGEventMaskBit(kCGEventMouseMoved) | CGEventMaskBit(kCGEventScrollWheel)| CGEventMaskBit(kCGEventFlagsChanged) | CGEventMaskBit(kCGEventKeyDown) | CGEventMaskBit(kCGEventKeyUp); DebugLog(@Event before: %x, eventMask); eventTap = CGEventTapCreate(kCGSessionEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, eventMask, MouseCallback, self); DebugLog(@Event after: %x, eventMask); if (!eventTap) { fprintf(stderr, Failed to create event tap\n); exit(1); } // Create a run loop source. runLoopSource = CFMachPortCreateRunLoopSource(/*kCFAllocatorDefault*/NULL, eventTap, 0); CFRelease(eventTap); // Add to the current run loop. CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop], runLoopSource, kCFRunLoopCommonModes); // Enable the event tap. CGEventTapEnable(eventTap, true); CFRelease(runLoopSource); ___ 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
NSMutableArray initWithCapacity and insertObject:atIndex
I would like to insert objects out of order into an NSMutableArray. I create the array with NSMutableArray* cards = [[NSMutableArray alloc] initWithCapacity:5]; When I try to call [cards insertObject:card atIndex:4]; I get the error: *** -[NSCFArray insertObject:atIndex:]: index (4) beyond bounds (1) Why doesn't this work? Thanks, Adam ___ 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: [iPhone 3.0; XCode 3.1.3] Question about when views are available for manipulation.
On Aug 8, 2009, at 1:23 AM, Brian Bruinewoud wrote: Hi, I'm a little confused about how this code works: MyController *myController = [[ myController alloc ] initWithNibName: @myView bundle: nil ]; [[ self navigationController ] pushViewController: myController animated: YES ]; myController.myProperty = itsValue; [ myController release ]; I always see the view set-up code (in this case myController.myProperty = itsValue) after the view has been displayed. It makes more sense to me to set up the view before calling pushViewController but this doesn't work. For example, if myProperty has a non-synthesized setter that expects IBOutlets to be bound it will be disappointed as they'll still be nil at this point. So, my questions are: Why doesn't initWithNibName create and bind all the IBOutlets before it returns? Because --- as Kyle Sluder stated --- laziness is a virtue, in operating systems and in programmers (but only if the latter use their laziness effectively) . . . The iPhone programming frameworks have a very simple set of design concepts for displaying data to the user of an iPhone application: opresent data in single screens oeach screen of presentable data is represented by a single UIView, which may have many associated sub-views (which fact is largely irrelevant) othat single screen / single UIView is created and managed by a UIViewController Initialisation of a UIViewController is done in one of two ways (skipping over details like the different ways to initialise Navigation Controllers or Table View Controllers): MyViewController *aController = [[MyViewController alloc] init]; or MyViewController *aController = [[MyViewController alloc] initWithNibName: @MyViewNib bundle: nil]; In both of these cases, all you have done is to allocate and initialise a View Controller.That's it. No further work is being done behind the scenes by the View Controller. In the first simple alloc-init style, the design assumption is that the View Controller will fabricate its managed view 'manually' *when the View Controller is asked to do so* by referencing its view property. In the second, initWithNibName style, the design assumption is that initWithNibName tells the newly allocated View Controller the name of the NIB that it *will* load (in the future) *when the View Controller is asked to do so* by referencing its view property. So, . . . Is the view guaranteed to be visible after pushViewController returns? Absolutely not.All you have done by invoking pushViewController is to push a View Controller onto the Navigation Controller's stack . . . Or is it still animating on another thread? The question is meaningless . . . Or is the request to display the view merely queued for the next loop through the RunLoop? Likewise . . . There's no need to bring threads and runloops into the picture (other than the regular old runloop and the main thread where all this activity is likely taking place).There is a very very simple sequence that's followed from application launch through to display of the initial screen by even the most complex iPhone applications. Given you have been talking about Navigation Controllers, the process of obtaining screens / views you can interact with programmatically starts when some other part of the program (maybe your application delegate or maybe some other View Controller) asks that Navigation Controller to supply its view and to place that view onto the window in some fashion. After that, the Navigation Controller will then ask the View Controller at the top of the Navigation stack for *its* view, and then the View Controller your were asking about earlier will go through the correct rituals to produce a screen / view of (one hopes) useful data for the end user. Similar situation with the call to makeKeyAndVisible - I've seen samples of applicationDidFinishLaunching where makeKeyAndVisible is called and then set up is done to the main window's view. I (and I am sure many others) would be highly interested to see these sample codes to which you refer.In general, if you make the window visible first and then load up your initial screen and add it to the window, the user will see a (possibly unpleasant) 'flash' as the new stuff is added. A more user-friendly approach is to (quickly) load the initial UI, add it to the window, and then display the window. I hope this has clarified some of the issues of View Controllers and Views . . . Cheers, . . . . . . . .Henry ___ 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
Re: NSMutableArray initWithCapacity and insertObject:atIndex
if you read the documentation on NSMutableArray it tells you exactly why! Capacity has nothing to do with the number of elements actually in the array and you can only insert an element with index less than or equal to the current count of the array. On Aug 10, 2009, at 12:59 PM, Adam Gerson wrote: I would like to insert objects out of order into an NSMutableArray. I create the array with NSMutableArray* cards = [[NSMutableArray alloc] initWithCapacity:5]; When I try to call [cards insertObject:card atIndex:4]; I get the error: *** -[NSCFArray insertObject:atIndex:]: index (4) beyond bounds (1) Why doesn't this work? Thanks, Adam ___ 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/rols%40rols.org This email sent to r...@rols.org ___ 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: NSMutableArray initWithCapacity and insertObject:atIndex
On Aug 9, 2009, at 9:59 PM, Adam Gerson wrote: I would like to insert objects out of order into an NSMutableArray. I create the array with NSMutableArray* cards = [[NSMutableArray alloc] initWithCapacity:5]; When I try to call [cards insertObject:card atIndex:4]; I get the error: *** -[NSCFArray insertObject:atIndex:]: index (4) beyond bounds (1) Why doesn't this work? Thanks, Adam Hi, Adam, -insertObject:atIndex: requires the index to be within the existing bounds of the array. -initWithCapacity: doesn't fill the array--it only gives your array an internal hint as to what its size may be; it isn't filling it, as you may know, with anything. On modern systems, my understanding is that the benefits of using - initWithCapacity: over -init are generally negligible. To reframe this: If you were to be inserting an object (card) at index 4 of your array (cards) after -initWithCapacity:, what would happen if you were to access the object at index 1, 2, or 3? You'll need to insert objects sequentially and build up to the proper array size with the card object at the right position. The documentation on the methods you referenced will likely be helpful on all these points. Cheers, Andrew ___ 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: NSMutableArray initWithCapacity and insertObject:atIndex
On Aug 9, 2009, at 9:59 PM, Adam Gerson wrote: I would like to insert objects out of order into an NSMutableArray. I create the array with NSMutableArray* cards = [[NSMutableArray alloc] initWithCapacity:5]; initWithCapacity simply makes an array large enough to contain that number of elements.initWithCapacity is just a suggestion to the class that you might want to start with that number of elements. When I try to call [cards insertObject:card atIndex:4]; I get the error: *** -[NSCFArray insertObject:atIndex:]: index (4) beyond bounds (1) Why doesn't this work? Based on the initialisation code, you have an array capable of holding five elements (with the potential for expanding as required), but that doesn't mean there are five elements in the array.After that initialisation, there are zero ( 0 ) elements in the array, and thus any attempt to store beyond the last element will fail. What you're apparently trying to do is have what's known as a 'sparse array'.Take a look at the NSIndexSet class to see if it helps you get where you want to go . . .. Another way to proceed (but for reasonably small arrays) would be to allocate an array of some size and initialise all its elements with instances of NSNull. This idea would work only in a limited universe of discourse --- clearly, if you wanted an element at 0 (zero) and another at (in Snow Leopard) 2 ^64, you're in trouble. Poke around on the web for sparse array implementation techniques . . . Cheers, . . . . . . . .Henry ___ 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