cocoa-touch

Storing optional NSNumber in Core Data

In my core data model, I have an entity with an optional NSNumber attribute. How do I test to see if the value in that attribute is valid or not? When I test for nil... doesn't work. [self numberAttribute] == nil // always returns NO When I test for a zero value int, that doesn't work. [[self numberAttribute] intValue] == 0 /...

Multiple views in a UIWindow

I have a "navigation based application" which also needs to have a view always displayed at the bottom of the screen at all times. I added this new view to a UIWindow after adding the UINavigationController's view: // In my delegate's applicationDidFinishLaunching method [window addSubview:navigationController.view]; [window insertSubvi...

How to know if user prefers miles or kilometers?

Hi, In my app I've got a certain distance in meters. And I want to display it in kilometers if user prefers kilometers and display it in miles if user prefers miles. And in the first case I want to add to a string "kilometers" at the end and in the second one to add "miles". What is the best way to achieve this goal? Thanks. ...

Can the cocos2d Director return time?

I am currently using the cocos2d Director for controlling my animation with the pause, resume, and stopAnimation methods. Is it also possible to use the Director to return the time that the animation has played? I am currently using this method: -(void)stopAnimation:(id)sender { //Timer initialized elsewhere: startTimer = [NSDate ...

Turning screen off

Hi, I need my application to be running without the iPhone going to sleep. But I'd like to turn the screen off. Something similar is done in the Phone application, when you speak on the phone. I prevent the iPhone from going to sleep in the following way: [ [UIApplication sharedApplication] setIdleTimerDisabled: YES]; But how can I tu...

Count the number of times a method is called in Cocoa-Touch?

I have a small app that uses cocos2d to run through four "levels" of a game in which each level is exactly the same thing. After the fourth level is run, I want to display an end game scene. The only way I have been able to handle this is by making four methods, one for each level. Gross. I have run into this situation several times ...

Scrolling to range in UITextView

I have a UITextView with text in it, and I want to be able to scroll it such that a given NSRange of the text is at the top of the view. Using scrollRangeToVisible: does not work: it will scroll the range such that it is somewhere in the view, not necessarily where I want it to be. How can I scroll such that this specific NSRange of text...

Play a sound of indefinite duration on the iPhone

I need to play a "horn" sound when a user touches the screen. The horn sound needs to play for as long as the user's finger remains in contact with the screen. The ending of the sound effect will be different. Imagine the horn "petering" out at the end as airflow decreases. Would I have to stitch 2 sound files together? Do I need to...

UIAlertViewDelegate method didDismissWithButtonIndex gets called while the phone is sleeping/locked.

I have a UIAlertView who's didDismissWithButtonIndex delegate method calls pops the view controller (same class, it's the alertview delegate and the viewcontroller) to return the user to the previous screen. The issue is that when you lock the phone before the [alert show]; is called, something is calling didDismissWithButtonIndex while ...

XCode Linking build error

This one is new to me. Not even sure what RootViewController.o is? though this project does have a .m & .h. Building for Simulator 3.0. Cleaned before build (Shift-⌘-K). Recently added some classes from another project that also had a RootViewController...but I didn't transfer old one over. Haven't built since. This could be part of th...

Purpose of a static library

I want to create an application core that connects to a webservice, downloads the data, parses it and then returns it to a view controller. This core would ideally handle requests from multiple controllers and abstract away a lot of repetitive code. Also, I want to potentially use this core for a mac os x application. Would these tasks...

EXC_BAD_ACCESS with Objective-C Properties

In my iPhone application, I have the following line in a constructor: self.myVar = myVar_in; where myVar is a property and myVar_in is a parameter passed to the constructor. When I run the code, I get an EXC_BAD_ACCESS error on this line. However, when I replace the line with: [myVar release]; [myVar_in retain]; myVar = myVar_in; t...

Why does my iPhone toolbar only animate the first time?

When I added a toolbar below a UITableView I want to show an activity indicator and label for few minutes to get values from a URL. I added this code in my project: NSArray *toolbarItems = [NSArray arrayWithObjects:[[UIBarButtonItem alloc] initWithCustomView:actview], [[UIBarButtonItem alloc] initWithCustomView:label], nil]; [toolbar ...

When to use a UIAlertView vs. UIActionSheet

Are there situations where a UIAlertView is better to use than a UIActionSheet? What are the typical scenarios where you would use one over the other? I'm programming a navigation bar button to open a UIWebView in an external application, and at first I started programming a UIAlertView, then I thought that an action sheet might be bett...

possible to simulate a touch event instead of didSelectRowAtIndexPath

In my previous question I was asking for a next button and it had to act as if the cell was selected. Some decent answers were given and I was satisfied for the moment. However, I noticed that the actions behind my cells depend on a touch. Now, I read some stuff on the UITouch and I was wondering is it possible to simulate a touch here...

UITabBarController initializes with nothing selected

I've got a UITabBarController in my project that I'm creating programmatically - without a nib. I create the view controllers, initialize them, and then create an array of them and use the setViewControllers:animated: method on my tab bar controller. This works except that when it appears, my tab bar controller doesn't have anything sele...

Hover Over State for UIButton on iPhone

I successfully created a custom keyboard that functions similarly to Apple's keyboard. There is one thing that remains different. On Apple's iPhone keyboard the user can swipe their finger across the keyboard and all of the keys they pass though will pop-up. On my keyboard this does not happen. Swiping your finger across will just re...

How do I determine if a coordinate is in the currently visible map region?

I have a list of several hundred locations and only want to display an MKPinAnnotation for those locations currently on the screen. The screen starts with the user's current location with a 2 mile radius. Of course, the user can scroll, and zoom on the screen. Right now, I wait for a map update event, and then loop through my location...

Adjusting iPhone TableSearch Algorithm to Prevent UI Delay

Much of my code is based off of Apple's TableSearch example, however my app contains 35,000 cells that need to be searched rather than the few in the example. There isn't much documentation online about UISearchDisplayController since it is relatively new. The code I am using is as follows: - (void)filterContentForSearchText:(NSString...

UIActionSheet cancel button strange behaviour

I have a UIBarButtonItem opening an action sheet to offer users choices about what to do. Everything works as expected unless I try to click on the "Cancel" button. The target of the button appears to have moved up from where it should be. I can only activate it by clicking somewhere in the middle of the "Cancel" and "Ok" buttons. I'...