objective-c

Alternative Control Structures

I've been wondering about alternative ways to write control structures like you can write your own language constructs in Forth. One that you learn early on for if statements is a replacement for this: if ( x ) { // true } else { // false } with this (sometimes this is more readable compared to lots of brackets): x ? true : fa...

What's the easiest way to work out the difference between two positive integers?

I just need to know the difference between two int variables a and b. I'm new to Objective-C. ...

How to preload or lazyload images in a UITableView on iPhone?

I'm having a problem when scrolling down and up a tableView on iPhone it gets kind of stuck while loading the images i need a method to preload the images so the scroll can be fluid or load the images 'till the scroll event stops... any help on this? ...

Is there a memory leak here?

Please see my comments in code: -(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t { [super init]; coordinate = c; NSDate *today = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateStyle:NSDateFormatterLongStyle]; NSString* formatted...

Multiple strings in openURL. iPhone SDK

Hello, I am making a twitter application for iPhone, I am trying to add a button which will open Safari, and take the user to their twitter homepage. I have a textfield called username, so the following code does not work, hopefully someone will be able to help me out. -(IBAction)viewAccount { [[UIApplication sharedApplication] ope...

Memory cleanup on returned array from static method (objective-c)

In objective-c, I have a utility class with a bunch of static methods that I call for various tasks. As an example, I have one method that returns an NSArray that I allocate in the static method. If I set the NSArray to autorelease, then some time later, the NSArray in my calling method (that is assigned to the returned pointer) losses...

NSDrawer delegate pointing to deallocated object?

A user has sent in a crash report with the stack trace listed below (I have not been able to reproduce the crash myself, but every other crash this user has reported has been a valid bug, even when I couldn't reproduce the effect). The application is a reference-counted Objective-C/Cocoa app. If I am interpreting it correctly, the cras...

Why check if your popoverController is nil? Doesn't Obj-C ignore messages to nil?

Pretty much everyone that writes about the UISplitView on the iPad uses the following code structure to dismiss a popover: if (popoverController != nil) { [popoverController dismissPopoverAnimated:YES]; } I though Objective-C was happy to ignore messages that are passed to nil? In fact, in the File > New Project > New Split View A...

GameKit server disconnect makes session invalid

Hi everyone, I'm trying to build a 4 player multiplayer game using GameKit. I tried many things and I'm currently using client/server mode, meaning that I have 1 session in GKSessionModeServer and 3 other sessions connecting to this one in GKSessionModeClient. My goal is, that when a user leaves the game or gets disconnected for whateve...

Parsing a simple XML from string in Cocoa?

I have a simple XML and I need to get the first 'id' from puid-list. I found lots of examples but none of them quite do that because of the namespace. How do get the id out as an NSString? PS: I'm on a Mac. <genpuid songs="1" xmlns:mip="http://musicip.com/ns/mip-1.0#"&gt; <track file="/htdocs/test.mp3" puid="0c9f2f0e-e72a-c461-9b9a-...

iPhone mapKit annotation for Current Location

Hello Im currently strugglung with annotations. how can i prevent the AnnotationLable for the blue GPS-point. (Here is an Image) - (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(MKAnnotation *) annotation{ if (annotation == mapView.userLocation) { return nil; } the function above isnt working, and i reali...

NSString stringWithFormat swizzled to allow missing format numbered args

Based on this SO question asked a few hours ago, I have decided to implement a swizzled method that will allow me to take a formatted NSString as the format arg into stringWithFormat, and have it not break when omitting one of the numbered arg references (%1$@, %2$@) I have it working, but this is the first copy, and seeing as this meth...

What is the best way to thumb through photos on the iPad?

I and a user to be able to thumb though photos on their iPad, how would I go about doing this via x-code, objective-C or the UI Builder? ...

Convert methods from Java-actionscript to ObjectiveC

Hi I'm tring to convert the following 3 methods from java-actionscript to Objective C. Part of my confusion I think is not knowing what Number types, primitives I should be using. ie in actionscript you have only Number, int, and uint. These are the 3 functions I am trying to convert public function normalize(value:Number, minimum:Num...

How can I create "glass" effect on my own UIViews?

Hi there, I'm working on an iPhone app that has some non-rectangular UI elements. Currently, I'm subclassing UIView, and in drawRect I'm using a CGPathRef to draw black border and a color-filled interior. I'd like to make these items look more like "buttons", though, so I'd like to have some of the same sort of "glass effects" that ar...

Trying to debug a 'Assertion failure in -[UIActionSheet showInView:]' error....

I am working through "Beginning iPad Application Development" and am getting hung up in Chapter 3 where I have created a project that works with an Action Sheet. As it stands now, my application loads into the simulator just fine with no errors that I am aware of, but as it runs, it crashes with the following errors showing up in the de...

Issue with CGEventTapCreate() call.

Hi All, I'm trying to register for global key events using this code : void function() { CFMachPortRef keyUpEventTap = CGEventTapCreate(kCGHIDEventTap,kCGHeadInsertEventTap,kCGEventTapOptionListenOnly,CGEventMaskBit(kCGEventKeyUp),&keyUpCallback,NULL); CFRunLoopSourceRef keyUpRunLoopSourceRef = CFMachPortCreateRunLoopSource(NULL, ke...

iphone quartz 2d easeoutBounce animation on text.

Scenario: I have created an app that show text randomly on iphone. After each 1 second, some 60-100 characters are drawn on screen using quartz 2d graphics. (OK thats easy). I want when the last character is shown it should be animated in easeoutBounce style. 1)How i will get the easeoutBounce effect? (You can check jquery easing plug...

Where to document code with Doxygen

Hello. I've never written documentation for any C-style code before (only done asdoc and phpdoc). I've been looking at Doxygen for documenting my Objective-C code, but I'm unsure where to put the comments. Should I document the .h files or should I add the comments to the .m files? or both? Any other recommendations? ...

differing methods of alloc / init / retaining an object in objective-c

In several pieces of sample objective-c code I've seen people create new objects like this: RootViewController *viewController = [[RootViewController alloc] init]; self.rootViewController = viewController; // self.rootViewController is a (nonatomic,retain) synthesized property [viewController release]; [window addSubview: [self.rootVie...