objective-c

iPhone 3.0 MapKit - Multiple Annotations in the Same Location

Background: I have created an application that allows users to submit an entry to an online database, and view other entries from that database. These entries contain geocodes for latitude and longitude which are used for positioning the annotations on the MapKit. Users can submit the location using either their current location or an ad...

Why does my NSNumberFormatter object print "2" for input 1.0?

That looks like a bug in the API: When my input CGFloat is 0.0, I get this: Input = 0.000000, Output = +0 When my input CGFloat is 1.0, I get this: Input = 1.000000, Output = +2 Obviously that's not what I want ;-) Now here is how I create that NSNumberFormatter object: NSNumberFormatter *formatter = [[NSNumberFormatter allo...

How to switch tabs and pushViewController at the same time?

I have two tabs in my app, the left tab is a normal UIViewController, right tab is a navigation controller with a table view inside it. I'd like to allow the user to press a button on the left tab and jump to a specific detail view that belongs to a specific row in the table view on the right tab. In the table view itself I have no prob...

Is performance affected by adding categories to a class.

I'm new to Cocoa and have a small question before I get carried away with using categories. Say you add a new method to NSString. Does that affect performance of normal NSString messages, or are category methods only checked when a method call does not match the standard method set? ...

Connecting IBOutlet to ViewController managed by a UITabBarController

I get a crazy error and I am unable to see why it happens. I have made a simple app that uses a TabBar to navigate 3 views. I created everything and added one UIImageView to each of the 3 ViewControllers that the TabBar manages. Everything works fine. In the app you are able to navigate the 3 views and see the 3 images. Now I add one UI...

How to fit a String into a rectangle?

I have an NSString and want to fit it into a rectangle. The rectangle has a specified size, lets say width=150 and height=30. When the String is short and has only one character, it can be as high as the rectangle. More specific: It can have a big font size. But if the string has too much characters and would exceed the bounds of the rec...

Why do AppleScript "tell" commands run a non-GUI instance of my GUI application in the background?

I'm writing a standard Cocoa application, and I've just started implementing AppleScript support for it. I've defined and implemented a property called testprop for my top-level application scripting class, and accessing it works just fine: if I launch an instance of my app and run the following AppleScript in Script Editor, I get the ou...

How to set content-type when using initWithContentsOfUrl

Basically I want to set Content-Type: application/json; in order to call a dot net web service and have it return json to an iphone application. At the moment I have NSString * jsonres = [[NSString alloc] initWithContentsOfURL:url]; What do I need instead in order to issue a blocking request ? ...

NSpoint from NSTextView insertion point

I have an NSTextView and require the coordinates of the insertion point to display a view there upon user interaction. There is a function to get the character index from an NSPoint. I am wondering if there is any easy way to do the opposite? Thanks for any help! ...

How do I execute code on Application startup in a Document-based app

I have a Cocoa document-based application. When the app launches, I want it to execute some code, which will create a dictionary that I need to be accessible to any document in the application, but I only want the dictionary created when I start the app, not when a new document is opened. Currently I have one controller class, which is ...

NSFileHandle readInBackgroundAndNotify does not work

Hi I'm using NSFileHandle's readInBackgroundAndNotify method to get notifications when a log file has been updated. I have the following code: - (void)startReading { NSString *logPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library/Logs/MyTestApp.log"]; NSFileHandle *fh = [NSFileHandle fileHandleForReadingAtPath:logP...

Storing iphone application data on low memory

I have some data structures in my app that I need to persist upon receiving 'didReceiveMemoryWarning' notification. The data is kind of a running log of all of the actions the user has performed with the app (which is a game) The data I have may not be a small amount (possible > few hundred KB) so plists don't seem to be the right solut...

[iPhone SDK]How to create a "To:"-Field like in mail?

Hello, does anyone know, how I can create a Textfield, like the "To" Field in Mail? I mean a field, where you can start typing the contacts name and all possible contacts appear in a List under your textfield. And when you select an entry, the entry is entered in your Textfield and shown as some sort of bubble. Has anyone an idea how to...

Parsing an XML file stored in the Documents directory of an iPhone application

NSXMLParser has three types of init. -> init -> initWith Data -> initWithContents of URL => But my xml file is stored at Application's Document directory, so how to parse a file which is stored at "Doc Dir" Thanks in advance. ...

MPMusicPlayerController stops sending notifications

I have a MPMusicPlayerController playing the entire iPod library and I'm subscribed to the notifications when tracks change etc. This is all working correctly When the end of the playlist is reached, MPMusicPlayerController sends a change of state notification and stops. When I re-start the player, music begins to play again but MPMus...

Objective C Leaks when releasing objects with UITableViewCell

I am running the following code in tableView:cellForRowAtIndexPath: File *file = [[File alloc] init]; file = [self.fileList objectAtIndex:row]; UIImage* theImage = file.fileIconImage; cell.imageView.image = theImage; cell.textLabel.text = file.fileName; cell.detailTextLabel.text = file.fileModificationDate; cell.accessoryType = UITable...

clever ways of tracking down bugs in Obj-C

I'm having a bug in my Objective C program which causes the machine to crash hip deep in some library methods, and it's all library methods down the stack to main (Which I haven't touched from the one XCode gave me). So, I have a bit of a mystery. The error I'm getting is: Program received signal: “EXC_BAD_ACCESS”. Now, I'm sure tha...

Using delegates for iphone 3.0 classes on older versions, specially the MKReverseGeocoderDelegate

I'm wondering what happens when I use a MKReverseGeocoderDelegate in my ViewController, but the application is running in 2.2.1. Because I'm supporting 2.2.1 but using 3.0 as Base SDK. I have already added the framework as soft linking to support working on 2.2.1 and I understand I have to prepare the code to check if the MKReverseGeoco...

How best to debug a crash within objc_msgSend?

I have a crash taking place when an NSAutoreleasePool drains. Presumably the pool is trying to deallocate an object that has been prematurely released by another piece of code. The crash I have is in the midst of objc_msgSend as it is trying to send a message to an object that doesn't exist anymore. Given the stack state, what tips/tric...

Why is my button clicked event being called 4 times?

Probably a noob question, but I'm trying to write a simple iPhone app that increments a label by the number of times a button is clicked. I have the following code: #import "Controller.h" int *i = 0; @implementation Controller - (IBAction)buttonClicked:(id)sender { NSString *numTimesClicked = [NSString stringWithFormat:@"%d...