cocoa-touch

Objective C - Remove last character from string

In Objective C for the iPhone, how would I remove the last character of a string using a button action. ...

How to keep model & controller separate from a CALayer based UI?

I'm trying to re-implement an old Reversi board game I wrote with a bit more of a snazzy UI. I've looked at Jens Alfke's GeekGameBoard code for inspiration, and CALayers looks like the way to go for implementing the UI. However, there is no clean separation of model and view in the GeekGameBoard code; the model is the view, which makes ...

Where to put local variables

I have a view who's methods are called by the accelerometer updates in the view controller. I need more than one method to use and change certain variables, for example one method initializes the variable and another updates their value with each accel update. I know if they were only used on one method I could declare them inside that...

How to check for an active Internet Connection on iPhone SDK?

I would like to check to see if I have an Internet connection on the iPhone using the Cocoa Touch libraries. I came up with a way to do this using an NSUrl. The way I did it seems a bit unreliable (because even Google could one day be down and relying on a 3rd party seems bad) and while I could check to see for a response from some othe...

Objective C - Adding characters at specific parts of a string

I have made a quadratic equation solver for the iPhone and when the text box is clicked, my own custom keypad appears. I have a button that changes whether the number is positive or negative. Right now I what happens is that when the button is pressed (0 - current value of text) is what is displayed in the text box, so if the number is p...

Why can't I seem to unarchive objects in an iPhone app that were archived by an OS X app?

I'm writing an iPhone app that is mainly centered around grid patterns, so I have a Pattern class which contains an NSMutableArray of NSMutableArrays. This class implements NSCoding, and it seems the following code works just fine in my iPhone app: GridPattern * pattern = [GridPattern patternWithWidth:8 height:8]; [pattern setValueAtCo...

Objective-c IBOutlet objects to be released?

If I tie some interface builder objects to another object as instance variables, do they need to be released in dealloc method of the parent object? The important point is that I declare my IBOutlets with key-value coding(@property) in (nonatomic, retain) mode. In my theory IBOutlet objects is created when initWithNibName:... method of m...

where did all the templates in xcode go?

After the recent update in xcode I seem to have lost all the template for cocoa touch and iphone templates. Under Cocoa Touch Classes in the new file dialog, I only have 3 choices: Objective-C class Objective-C test case class and UIViewController subclass where did the others go? UITableView, UInavigation etc.? I am running xcode 3....

Adding a Flip View type controller in the middle of a UINavigationController hierarchy

I currently have a UINavigationController based application that works just fine. I'd like to take one of the view controllers that's a few levels deep into the UINavigationController stack to have a "flip side" type view as demonstrated by Utility apps, etc. Very common thing. The problem here is that I created an intermediate view con...

Can't release object without crashing

In a tableview cellForRowAtIndexPath, I do the following: MapViewController *mapView = [[MapViewController alloc] initWithCoordinates:city.Latitude longitude:city.Longitude]; [cell addSubview:mapView.view]; //[mapView release]; -- will crash here Calling the last line gives this memory error EXC__BAD _ACCESS”. How do I release the ab...

Casting sender parameter

I have a method that accepts a sender and is called with a UIbutton. How do I get that object to casted into a UIImageView? Basically how do I re-use the code for the button. - (IBAction)startClick:(id)sender { button.animationImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"Pic_1.png...

Convert NSValue to NSDecimalNumber

I've got a plist (created in XCode) with an array full of "Numbers" (0.01, 1, 2, 6) that unpacks into NSValues when reconstituted with initWithContentsOfFile. How can I turn these NSValues into NSDecimalNumbers that I can use for adding together? They will be treated as currency values so only need precision of 2 (maybe 4) decimal place...

Objective C - Using insertString for an NSMutable string

With a NSMutableString, how would I insert a "-" sign at the index "0" for an NSMutableString called "a". Right now my code looks like this: a = [insertString: @"-" atIndex: 0]; Xcode throws an error saying that 'insertString' is undeclared. Something looks very wrong with my code. Please give me guidance. ...

Objective C - Using deleteCharactersInRange for NSMutableStrings

How would I use deleteCharactersInRange to remove the first character of a NSMutableString? ...

Objective C - What is the value of a UITextField with nothing in it

I want to refer to the value of an empty text field because I want make an if function that if there is nothing in the UITextField the text of the UITextField will become "nothing". ...

Objective-C - Guidance on how to make a grapher

After making a quadratic equation solver for the iPhone I want to take it a step further by giving the user the ability to view the graph of the solved quadratic equation. I need some guidance on how to do so using the iPhone SDK and the available frameworks. ...

Is there a way to delete all iPhone application data?

Update: The app is running on the device of an ad-hoc user. I just want to delete a single application's data. Original question: Is there a way to completely wipe the an iPhone application's directory easily? I want to delete preferences, documents, caches, everything. I'd like to do this programmatically within the app so I cou...

Linking Static Libraries in iPhone SDK 3.0

I have an iPhone app that heavily relies on the OpenCV library; as such, I've compiled a static version of this library for inclusion with my app. The instructions for doing this are relatively straightforward: Using OpenCV on iPhone. The only gotcha I ran into was setting the linker flag, STANDARD_C_PLUS_PLUS_LIBRARY_TYPE to "standard...

String length with given font to fit UITextView 2 - The Return

In this question I asked for a good way to truncate a string to fit a given UITextView. Since there was no way provided by the SDK directly, I've ended up writing the recursive method below (only called by the following public method). However, this doesn't work unless I subtract a fudge factor of 15 (kFudgeFactor) from the field width w...

objective-c memory management: caching view elements

Hi, I'm writing an application which is quite graphically heavy and therefore I'm trying to implement a caching mechanism within my view controller that creates a view once, and retains it for future use, similar to the following: - (UIView *)logoView { if(_logoView == nil) { _logoView = [[UIImageView alloc] initWithImag...