objective-c

UIWindow and UIView addSubview Question

Does the addSubview method actually load the view into the application or not? The reason I am asking is because I have two two views in my application. The application delegate adds the two views as subviews and then brings one of the views up front. Now, I have a print statement in each of the viewDidLoad methods for each view. When I ...

Objective-C - Determining IP address of iPod touch programmatically

I'm programming in objective-C for several iPod devices and I was wondering about something. I'm developing an application that utilizes the server-client model and I'm using the UDP protocol with C sockets. Is there a class out there that allows me to determine the iPod devices IP address? After googling around other forums, I haven't f...

Car turning circle and moving the sprite

I would like to use Cocos2d on the iPhone to draw a 2D car and make it steer from left to right in a natural way. Here is what I tried: Calculate the angle of the wheels and just move it to the destination point where the wheels point to. But this creates a very unnatural feel. The car drifts half the time After that I started some r...

(Obj) C++: Instantiate (reference to) class from template, access its members?

Hi-- I'm trying to fix something in some Objective C++ (?!) code. I don't know either of those languages, or any of the relevant APIs or the codebase, so I'm getting stymied left and right. Say I have: Vector<char, sizeof 'a'>& sourceData(); sourceData->append('f'); When i try to compile that, I get: error: request for member '...

How can I tell if a button is being pressed in my iPhone app?

How can you tell when a button is being pressed? Specifically, how can you do something while a button is down? ...

Implementing -hash / -isEqual: / -isEqualTo...: for Objective-C collections

Note: The following SO questions are related, but neither they nor the linked resources seem to fully answer my questions, particularly in relation to implementing equality tests for collections of objects. Best practices for overriding -isEqual: and -hash Techniques for implementing -hash on mutable Cocoa objects Background NSObj...

NSFetchedResultsController with sections created by first letter of a string

Learning Core Data on the iPhone... There seems to be few examples on Core Data tables with sections. The CoreDataBooks example uses sections, but they're generated from full strings within the model. I want to organize the Core Data table into sections by the first letter of a last name, ala the Address Book. ... I could go in and cr...

Can't figure out where memory leak comes from.

Hello everyone! I'm somewhat of a cocoa newbie and I simply can't figure out why I'm getting a spike in the leaks graph in Instruments with this code. It seems to be a small leak (i.e. 16 Bytes and the Leaked Object is "Generalblock-16"; that is the only leaking object and says Self 100%) and it seems to remain that size regardless of wh...

How to avoid reference count underflow in _NSCFURLProtocolBridge in custom NSURLProtocol in GC environment

The basics are I have a custom NSURLProtocol. In startLoading, [self client] is of type: <_NSCFURLProtocolBridge> {NSURLProtocol, CFURLProtocol} The problem is running this in a garbage-collected environment. Because I'm writing a screensaver, I'm forced to make it garbage-collected. However, the _NSCFURLProtocolBridge protocol see...

Why does my program crash when accessing a property with self. and a synthesized accessor?

I have data object class: @interface Item: NSObject { NSString *title; NSString *text; } @property (copy) NSString *title; @property (copy) NSString *text; @end @implementation Item @synthesize text; - (void)updateText { self.text=@"new text"; } - (NSString *)title { return title; } - (void)setTitle:(NSString *)aS...

Error: expected ';' before 'interface' in Xcode

I'm trying to run through the Hello World tutorial for the iPhone and i get this error: Error: expected ';' before 'interface' I have checked and my files are identical (except for whitespace) to the tutorials, and i can't figure out why i'm having this problem. I can provide code if necessary. HelloWorldAppDelegate.h: // // HelloWorl...

WebPageContent problem

I have parsed some data from webpage content and stored it as an NSString. In that string there is a unicode character (\u0097). How can i remove or replace this and avoid all unicode characters? I tried using this line but it hasn't worked: [webpagecontent stringByReplacingOccurrencesOfString:@"\\u0097" withString:@" "]; Can anyone ...

How to know whether a UITextField contains a specific character

How would I say that if a UITextField has @"-" in it, do something. Right now my code is like this. It doesn't seem to work: if (MyUITextField.text == @"-") { NSRange range = {0,1}; [a deleteCharactersInRange:range]; MyUITextField.text = MyUILabel.text; } I know that I am doing something very wrong with the code. Please he...

Keyboard not disappearing when i press "Done" on the iPhone

I am trying to implement a hello world application for the iPhone and i've worked through some. However i can't figure out how to get the keyboard to go away. I've seen this and no it doesn't help (i have resignFirstResponder in my code). I have connected the relevant textfield to the file's owner as a delegate. Here is the code that det...

Dynamic typing and return values in Objective-C

Hello! I have run into a very strange behaviour I can’t make sense of. I have a Texture class with contentWidth property of type int. This class is wrapped in a Image class that has a width property of type int. The width of an Image is computed simply as the contentWidth of the underlying texture: - (int) width { return texture.co...

Unusual Bug in iPhone Application

In my hello world application, i have a button and a text field set up. You enter your name in the text field then press the button, then you're supposed to see "Hello, [name]!". However all i get is "Hello, World!" (the default for when there's no string in the text box), even when i input a name. As requested, here's the file: // // ...

Limit a double to two decimal places

How do I achieve the following conversion from double to a string: 1.4324 => "1.43" 9.4000 => "9.4" 43.000 => "43" ie I want to round to to decimal places but dont want any trailing zeros, ie i dont want 9.4 => "9.40" (wrong) 43.000 => "43.00" (wrong) So this code which I have now doesn't work as it displays excess twos: [NSString...

Placing elements into the UITableView footer, when to release them?

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { AViewController * aView = [[AViewController alloc] initWithNibName:@"myNib" bundle:[NSBundle mainBundle]]; return vintagePriceRowView.view; } I know this code needs a release... somewhere. But where? If I set the allocated AviewContro...

Global variables in Objective-C

In Actionscript you can have global variables like this: var number : Number = 15; And then use it in a method/function. How do you do that in Objective-c, is it possible? ...

IDE for Objective C

What are the IDE's or development tools best suited for projects involving Objective C, C and C++? Is there a common IDE which would support all the three languages. ...