objective-c

Unit Testing for NSError's

Hallo, I am trying to set up some unit tests for code that accepts an *NSError as an argument. If there is a validation problem, then the object is not saved and the NSError condition is set. My method is: - (BOOL)validateConsistency:(NSError **)error { ... code omitted for brevity ... if (errorCondition == YES) { N...

Loading images for multiple UITableView using lazy loading

Hi, I am developing an iPhone application with multiple table view. On each UITableview I have to load RSS feed data. Each feed has its own image. For a single feed, I try to parse the xml and load the image inside the delegate itself. Can any one advise me how to implement the lazy loading for all Rss feed view? ...

Set UITextField as phone number

/*h file:*/ IBOutlet UITextField *Number; /*m File:*/ [(Number) setText: [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"]]; Any idea why this is not working ? Thanks ...

objective-c memory management question

If I have a UIPopoverController (in .h file) and alloc init it multiple times in the same .m file. do I need to release it once to multiple times? ...

floor double by decimal place

Hi, i want to floor a double by its decimal place with variable decimal length (in iphone sdk). here some examples to show you what i mean NSLog(@"%f",[self floorMyNumber:34.52462 toPlace:2); // should return 34.52 NSLog(@"%f",[self floorMyNumber:34.52662 toPlace:2); // should return 34.52 NSLog(@"%f",[self floorMyNumber:34.52432 toP...

Will Objective-C make more sense if I learn Java programming?

Hi, I am looking to learn Java to make a few Android apps but what I am wondering is if I learn Java, will Objective-C make alot more sense to me? I did hear something like this a while ago on some tutorial but am not sure. Thanks ...

Collision detection using mulitple subviews within a moving view.

I am working on a game in OBJ C that has a ball view and a stage view. The stage view has 4 subviews. All views are UIImageViews. I have a method for collision detection that is working. I would like to expand it to more than 4 subviews without simply creating more lines of code. Looking at the code below, is there a way to simplify this...

Strange Problem with disappearing Cells containing UITextFields in UITableView

I have a screen which functions similarly to the address book contact screen. The screen displays some data in a UITableView and provides an "Edit" button. When the user presses "Edit" the UITableView is animated to display the data in "Edit Mode". There is not a 1:1 relationship between the fields in "View Mode" and the fields in "...

Save Username & Pass Objective C iPhone

i have a textfield, Number and Password i have no clue how to save these settings and then read them as the app starts to check if they have been set or not. Thanks Mason ...

Is it possible to update views while doing a task without multithreading in iPhone OS?

I'm trying to set up a view that gives feed back via progress bar while it carries out a task, by incrementally sending updates to the view. I don't know much about multithreading, so I'm trying to do this without using it. Is there a way to force a view to update? It seems like there should be something to do this, cause I'm not really...

How to stop mouse drag events from moving entire window? [cocoa]

I think this should be a very easy one, but I cant find the answer on the docs. I want to stop mouse dragging events which are in (or start in) my custom nsview subclass from causing the window to be dragged around the screen. How can I tell the window to stay still so i can interact with the view instead of dragging the whole window ar...

Is ConnectionKit still usable?

I'm writing a Cocoa app that will need access to multiple file transfer protocols, such as FTP, Amazon S3, etc, and I was planning on using the ConnectionKit framework to implement them. However, even though I managed to get it compiled (which is quite a feat itself), it seems to be missing a number of it's header files, such as the S3 p...

InitWith Methods vs. Factory Methods

I'm picking up ObjC and Cocoa, which is also my first serious foray into programming in general. I'm having trouble with the differences between initWith methods, which are called on instances, and factory methods, which are called on classes. Firstly, why are they called "factory" methods, and is there a proper term for what I've dubb...

NSDictionary stringForKey: and Casting [NSNull null] to NSString*

I was recently told casting [NSNull null] to (NSString*) was "terrible". However, -[NSDictionary stringForKey:] method will return [NSNull null] if the key is not in the dictionary, and if I don't do the cast the compiler yells at me. Am I missing something? EDIT: My mistake... and I think I might be beginning to see the problem....

require that an object passed into an objective C method conform to a protocol?

Is this possible? For example, I have a class TriangleDataView with an init method. Currently the method is declared like this: - (id)initWithFrame:(CGRect)frame delegate: (id) delegateObject; I would like to require that delegateObject conform to the UITextFieldDelegate protocol. But what is the syntax for that? ...

Objective C: Version of JSON library I'm compiling in present in another library I'm linking in via .a, how to resolve conflict?

I'm compiling in a local version of the SBJson library into my iPad project. I just started linking in a static .a library that has compiled symbols that collide with objects in the SBJson library. I am able to modify the SBJson library, what is the best way to modify it to avoid the name collisions? ...

Best practice for UIKeyboard notifications - iPhone SDK

Hi all, I have a drill down navigation app with three levels of UIViewControllers. In each view controller, I have a UITextField where I am trying to subclass the UIKeyboard for each. My question is where to "set" notifications and "unset" them. I have the notifications: [[NSNotificationCenter defaultCenter] addObserver:self selecto...

Question about releasing an ivar with the Copy property

If I have a class @interface Foo { NSString *temp; } @property(nonatomic, copy) NSString *temp; @end I understand that upon assignment, the old temp will get released and the new one will be assigned using temp = [newTemp copy]. And going by memory management rules, you are supposed to do [temp release] in the dealloc method of...

Use Address Book as Data Source

I am going to use Address Book as my app's data source for use to add new contact or select a contact. The contact is mainly for company or organization, but it can be a person. For adding a new contact, I would like to show a list of contacts, like people pick control: However, I cannot figure out to change Cancel to Add, and Groups...

How do I make toolbars that look like the ones in Keynote?

Here's a screenshot of keynote on the ipad: The toolbar is pretty flat - it doesn't have a vertical gradient the way the builtin toolbar styles do. I've played with the different styles, the translucent flag, and the tint color, and haven't been able to replicate it. How are they doing this? How would I implement it? ...