objective-c

CoreData: Checking for Null

I have a CoreData entity (waypoint) with a foreign key to another entity (track). When the foreign key is set, or if it is not set, this if statement works fine: if ([wp track]) { thirdLabel.text = [NSString stringWithFormat:@"Part of Track: %@", [[wp track] title]]; } However, if the track that the waypoint is keyed to has been del...

Lerp between two CGPoints to get values of ALL pixels in between?

I'm trying to lerp between two CGPoints to get the values of all the pixels in between. I'm trying to find a simpler solution since right now I have a confusing recursive mess. The problem is that lerping between two points produces a point in between the two. Now I have two groups of points to lerp through... There has to be an easier...

How do you drag-and-drop from a TableView's icon to a stationary icon?

How do we go about coding drag-and-drop (or tap-and-drag) from a cell in a TableView on an iPhone? I'd like to have a set of drop destination icons that are stationary. I've been trying touchesBegan, touchesMoved and touchedEnded methods. These events fire nicely from a View so I can get a swipe to work nicely. Most likely the destinatio...

Current Text Direction (BiDi support) in Cocoa?

Hello! I recently received an Arabic translation for my app, but would like to do more than simply replace the strings. I can re-layout most of the NIBs with Interface builder, but there are a few things that I need to do programmatically. Is there some way in Cocoa to figure out if the current locale is a RightToLeft locale, or do I...

Why can't I set my button's shadow colour?

I'm trying to set the shadow colour on a UIButton, but all I seem to be able to get is a mid grey. UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; button.frame = CGRectMake(20, 20, 200, 100); [button setTitle:@"a" forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonPressed:) for...

UIAlertView in Landscape mode

I have set my iPhone in the landscape mode but when I try to display the UIAlertView its come in the portrait mode. How it will display in landscape mode? ...

Error when retaining NS(Mutable)Array in a class

Hi, I'm having a hard time working with arrays. Coming from AS2/AS3 and garbage collection is new to me ... ;) This is not the full code, just the parts that matter. .h-file @interface HelperViewController : UIViewController { NSMutableArray *pagesNumbers; } @property (nonatomic, retain) NSMutableArray *pagesNumbers; .m-file @syn...

How would you parse the integer out of this XML response in Obj C?

I am working with an API where I get a response back this this, and I want to parse the integer ID out of it: <?xml version="1.0"?> <trip>328925</trip> How would you parse this? I have some really fragile code I want to get rid of, and I'd appreciate some advice: if ([[response substringWithRange:NSMakeRange(0, 21)] isEqualToStr...

understanding methods in objective-c

for example we use this method in the tableview - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 16; } i want to learn we don't call this method in anywhere but application reads this value how is it being? there are a lot of methods like this we did not call. ...

Fetched property and NSPredicate

I know how to use NSPredicate with relationships but for some reason when I do the same thing with a fetched property I get: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath address.id not found...' where address is a fetched property. The code is like this: [NSPredicate predicateWithFormat:@"...

Capturing all methods/message calls on an object

How do I put a "hook" on an object so I can see what messages are being sent to it? (ie do an NSLog() every time a message is sent to an object). I think recall seeing this done before but I forget how. I am thinking it might help me track down why part of my code is not working. ...

How can I make the keyboard disappear?

Is there a way to make a keyboard disappear without resignFirstResponder? I have a UITextField, and I'd like it to be able to accept new text and still have the insertion point (flashing cursor) visible without the keyboard being on screen. When I perform a [textField resignFirstResponder] I can still insert text, by appending to the t...

NSArrayController/NSTreeController and Cocoa Views

Hi, i've been reading for a while a little bit of Objective C and Cocoa, and i have to say that although i am thrilled with the overall simplicity of Objective-C, I feel totaly lost regarding Cocoa and especially the MVC design pattern. The Cocoa books I've read, ask the reader to just complete a set of steps for a program to work, with...

Why the Observer in NSNotification called twice.... ?

If the class is a custom class, after posting the notification, the selector corresponding to the observer is called twice.. Is there any better solution so that the selector is called only once? ...

Generating a String from CLLocationDegrees, e.g. in NSLog or StringWithFormat.

Hello Stacked-Experts! My question: How to generate a string from a CLLocationDegrees value? Failed attempts: 1. NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers. 2. NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude]; 3. NSString *tmp = [[NSString alloc] ini...

Cleaning up Objective-C code

When working on complex problems, I find myself trying all sorts of solutions and, while doing my best to stay organized, the code can get quite messy. Objects may be changed and no longer be of use, while other times I may add snippets of code that do not end up being used by the program but are taking up space and possibly memory. Asi...

refreshing my applicationData ( actually my Title )

I seem to be having a problem with the titles in my application. Let me describe what is happening here. 1) starts out good with the correct image http://img262.imageshack.us/img262/5808/picture15b.png 2) still good after clicking a cell http://img31.imageshack.us/img31/4440/picture13dvg.png 3) after hitting the backbutton previo...

SCEvents doesn't work in some methods??

Hi, [Note: The title may be less than accurate, I didn't know how else to phrase it] For some reason NSFileHandle's readInBackground didn't work so I resorted to SCEvents, a Cocoa wrapper around Mac OS X's FSEvents API. I have a separate class called "EventListener" that handles all the SCEvents stuff. It has these methods: - (void)se...

Why are there more files/hardlinks with the same iNode than the reference count shows?

I have recursed a folder on a single volume, and retrieved a list of filenames, reference-counts and inode numbers, using NSFileManager attributesOfItemAtPath and NSDictionary fileSystemFileNumber and objectForKey:NSFileReferenceCount For some reason I am getting results such as a reference count of 10, but a list of many more than 10...

Create an array of all the items in the sub arrays of an array of arrays?

Did I say "array" enough for you there? To clarify: I'm working on organizing and array in an iPhone project. I have an array of arrays. Each sub array has a list of items. How can I make a new array of all the items contained in the sub arrays? I've experimented with the addObjectsFromArray function with little luck. Thanks! ...