objective-c

SizeToFit on a UIScrollView's content size

A UIView has a SizeToFit method that will make the UIView fit all of it's subviews. Is there anything like that, which will just return the size that it calculates and not modify any view's frame. I have several subviews on a UIScrollView and I want to do SizeToFit on the scroll view's contentSize, rather than it's frame. I have to do i...

Turning an NSArray of custom objects into a alphabetically sectioned UITableView with an index?

(hmm.. long title) If I start out with an NSArray of custom objects (each object is a Person) like this: { surname:Allen forename: Woody, surname:Baxter forename: Stanley, surname:Clay forename: Cassius } ..etc.. You can see that the array is already in surname order. How do I use that array to create a a UITableView wit...

Bug in PhotoScroller code from WWDC 2010 Session 104 - Designing Apps with Scroll Views

I am trying to track down a bug in the sample code provided for the WWDC Session 104 - Designing Apps with Scroll Views: "PhotoScroller" It is a mutated while being enumerated error that only happens on occasion when paging from a zoomed image to one of the other images. I am using part of this code in one of my apps and am desperately ...

Create NSArray from plist array

I need to pull out data from a plist array and put it in an NSArray. But it seems to not be working. Here is my main file: NSString *path = [[NSBundle mainBundle] pathForResource:@"htmlData" ofType:@"plist"]; NSMutableDictionary *tempDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path]; dictionary = tempDictionary; [...

Should I use a UIButton or a simple UITapGestureRecognizer

I'm creating an iOS user interface with a lot of different UIImageViews that will trigger actions when tapped (once is enough). I have the choice between using UIButtons with a custom view (the image) or just setting up a bunch of UIImageviews with an associated UITapGestureRecognizers. In terms of functionality I get the same expected r...

Is Cocoa Programming for Mac OS X (3rd edition) outdated?

Hi Stack Overflow, got a quick question for you (pretty much the title): is the book Cocoa Programming for Mac OS X (3rd Edition) outdated? It's just that I read a little in it, until page 36 (in a .PDF ebook version) where I came across a problem. The chapter introduces you to Objective-C and Cocoa, and you already have to write a pro...

Simulating a candle flame in Objective C

As part of a current project I've been asked to display a candle onscreen. Users should be able to tilt the device to tilt the flame, and perform an action (eg. tap) to blow out the flame. I'm at a real loss on how to achieve this. Some ideas I've had: purchase a movie of a candle from a stock video site. This won't let me tilt or blow...

ABPersonViewController drawn under the navgation bar

The context: I am working on an app that maintains a list of contacts along with their record IDs for it's own reference. When the user needs to change the number associated with a specific contact within the app, I am trying to display the ABPersonViewController so the user can choose the new number from the contact in AB. The probl...

Should I release a pointer that's pointing to an item in an array?

Not quite sure how to phrase this, but should I release a variable in this situtation: NSString *string = @"HELLO WORLD"; NSArray *array = [NSArray arrayWithObject:string]; NSString *shouldIReleaseThis = [array objectAtIndex:0]; NSLog(@"%@", shouldIReleaseThis); //???? [shouldIReleaseThis release] ?????? //Do stuff with array Shou...

Get an integer from a plist for Objective-C iPhone dev.

I have the following DataAll.plist: <array> <dict> <key>ID</key> <integer>1</integer> <key>Name</key> <string>Inigo Montoya</string> </dict> .... </array> I want to get the ID value from it. My code gets the Name correctly, but the ID is a weird value. Here's what I'm doing: NSBundle *bundl...

Most effective way to populate a picker view with range of integers?

I have a simple UI picker view in an iOS app (iPhone) and I'm looking to pre-populate it with a range of numbers on launch. What would be the most pragmatic/quickest/optimized way to populate it? I'm new to iOS development, so I'm just starting to test the waters. The documentation is pretty decent but I'd like to get some insight fro...

How can I create my own UITabBar?

Hi all, Further to this question here, I'm really interested in creating my own UITabBar, and 'rolling my own'. Im really curious as to how this is done, especially in an app such as the Twitter app. How can I do this? Can anyone point to any good resources on how to subclass this? Should I do it programmatically, or in a XIB? Edit: I...

incorrect file size when converting file to NSdata in Objective C

Hi, i has the following code which suppose to convert file to data but the problem is the byte size is not the size after the conversion can someone help me on this one? i'm suppose to send the NSdata using NSStream to a server. NSString *file = [[NSString alloc] initWithContentsOfFile:filepath; NSLog(@"length = %d",[file length]); //...

facebook graph API and parsing results in objective-C

I am calling this: facebook requestWithGraphPath:@"me/friends" andDelegate:self] Now I am confused on what facbook returns to me in the delegate? How should I parse this in the (void) request:(FBRequest*) request didLoad:(id) result method? Is it returned as a dictionary? ...

Premature exit from dispatch_asycn , Grand Central Dispatch..

Lets say i am running some code in dispatch async. .. is there a way to terminate the thread it creates before it completes? like when the user clicks cancel dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ //start doing something here.. break bofore it finishes? dispatch_async(dispatch_get_ma...

Objective C - Strategy Pattern ???

I understand the concept of the "strategy pattern" but i am still a little bit confused. Let'say we have a class named Dog Dog has MovementBehaviour (interface) which can be MovementBehaviourNormal & MovementBehaviourFast MovementBehaviourNormal and MovementBehaviourFast both contain a method named move QUESTION: what is the best way t...

What's the equivlent code for stringWithContentsOfURL using a NSURLRequest?

Hi, I used to have: NSURL *url = [NSURL URLWithString:escapedUrlString]; NSString *responseString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; But, I was reading online that I should probably be using an NSURLRequest instead if I want to add a timeout. The first code works fine, but the second co...

Help needed on error while sending NSData to server via NSStream in objective c

Hi, i'm have problem with the writing TCP socket in objective c. i'm having the following error when i then to write a data to my server. my file size is 2727936 but while sending the data, the code cashed after sending 1000000+ byte. is something wrong with my code? or do i need to need something else? Thanks in advance. error=> malloc:...

Using Cocoa / Objective-C, get currently connected network's security type in Mac OS X

How do I get the security type (and other information) of the currently connected network in Airport in my Objective-C / Cocoa program? ...

NSDate formatter Problem its getting null while converting NSString to NSDate

hi to all I am Struggling to convert NSString to NSDate with the Help of formatter but its going to be null Can any one help please here is my code... NSString *dateString=[NSString stringWithFormat:@"10/26/2010/09:56:56 PM"]; NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init] autorelease]; [dateFormat setDateFormat:@"mm/d...