objective-c

Xcode: What's up with the .NIB -> .XIB?

Hi, What's up with the NIB->XIB change somewhere between Xcode 3.0 to 3.1? Is there any difference with this name change that I should know while I go through tutorials that mention nothing but the .nib file? ...

Random number function is misfiring

I have a very simple iPhone app that requires a random integer from 1-100. I have a button that calls the random number function then displays it. -(IBAction)buttonReleased; { srandom(time(NULL)); int theNum = random() % 100 + 1; numberDisplay.text = [NSString stringWithFormat:@"%d", theNum]; } The problem is, if I press...

iPhone short animation: video or image sequence?

I have read several post on both matters but I haven't seen anyone comparing so far. Suppose I just want full screen animation without any transparency etc, just a couple of seconds animation (1''-2'') when an app starts. Does anyone know how "video" compares to "sequence of images" (320x480 @ 30) on the iPhone, regarding performance et...

UILabel place as portrait

I create a label in my iPhone application as: UILabel * lab=[[UILabel alloc]initWithFrame:CGRactMake(100.0,100.0,100.0,10.0)]; lab.text=@"1 2 3 4 5 6 7 8 9 0"; And also added window as subview. Now this label appearing in my view as: 1 2 3 4 5 6 7 8 9 0 I want it as: 1 2 3 4 5 6 7 8 9 0 I mean it will appear as portrait mode. Is ...

iPhone performance with Bitmaps

Pretty new to iPhone / objective-C. I have an application that has 15-100 small images (16x16 or 8x8 PNG) on the screen. For this example sake, let's assume that I can create these images using CGContext if I needed to. I would have to assume that iPhone would perform better using that method rather than loading images (PNG's). H...

Optimizing a Cocoa/Objective-C search

I'm performing a search of a large plist file which contains dictionaries, tens of thousands of them, each with 2 key/string pairs. My search algorithms goes through the dictionaries, and when it finds a text match in either of the strings in the dictionary, the contents of the dictionary are inserted. Here is how it works: NSDictionary...

How to get rid of the date and time that appears before every NSLog statement in the console

Hi, I use NSLog in my application. And I'd like to get rid of the annoying beginning of each string: "2009-07-01 21:11:06.508 MyApp[1191:207]". Is there a way to do so? Probably another logging function? Thanks. ...

How do I get the current date in Cocoa

I'm getting started developing for the iPhone and as such I am looking at different tutorials online as well as trying some different things out myself. Currently, I'm trying to create a countdown until midnight. To get the number of hour, minutes, and seconds, I do the following (which I found somewhere): NSDate* now = [NSDate date]; ...

iPhone: Logging to a file

Hi, I want to log my log strings to a file. I implemented the following method: void QuietLog (NSString *format, ...) { if (format == nil) { printf("nil\n"); return; } va_list argList; va_start(argList, format); NSMutableString *s = [[NSMutableString alloc] initWithFormat:format ...

Photo button like in contacts and Facebook app

How can I create a "person photo" button like the one in contact info or in the Facebook app? (grey and rounded border with a small radius and an image that is cropped inside it) Edit: It must obviously work for all photos, not just one that I prerender in Photoshop. I guess I could do it manually using masks etc., but Facebook app do...

Calling functions from within function(float *VeryBigArray,long SizeofArray) from within objC method fails with EXC_BAD_ACCESS

Ok I finally found the problem. It was inside the C function(CarbonTuner2) not the objC method. I was creating inside the function an array of the same size as the file size so if the filesize was big it created a really big array and my guess is that when I called another function from there, the local variables were put on the stack w...

Creating an NSArray initialized with count N, all of the same object

I want to create an NSArray with objects of the same value (say NSNumber all initialized to 1) but the count is based on another variable. There doesn't seem to be a way to do this with any of the intializers for NSArray except for one that deals with C-style array. Any idea if there is a short way to do this? This is what I am lookin...

Changing value of a NSNumber

Is there a way to change the value contained in an NSNumber after it is created without making it point to a different NSNumber? NSNumber *num = [NSNumber numberWithInt:0]; num = [NSNumber numberWithInt: 1]; // now num points to a different object, which I don't want. I want it the same object still, but different value. ...

Should you set the delegate to nil in the class using the delegate or in the class itself

If class A is using class B and class A is class B's delegate, is it ok if the delegate is set to nil in class B's dealloc? I have seen code usually resetting the delegate to nil inside class A's dealloc but wasn't sure the real difference doing it one way or the other. e.g. This is the usual way: // somewhere in class A - (void) some...

Enumerating array which contains a dictionary produces unexpected output

My question is why does it output the last 4 lines in the log(see below)...those objects are part of the dictionary printed earlier in the log & should not be located at the end of the array? I am missing something fundamental here... thx NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSURL URLWithString: @"www...

Persistent UIBarButtonItem in UIToolbar?

I've been developing an iPhone app that uses a UIToolbar (in the context of a UINavigationController) to display a small status icon at the bottom of the screen. The toolbar will eventually also have action icons associated with it (think Mail application). I'm running into an issue where it appears that each UIViewController pushed ont...

Objective-C dot syntax tricks for when Key-Value won't work?

I'm iterating through some objects and trying to set some properties that, apparently, don't like Key-Value coding. so I'm unable to create a string at runtime to represent the "key". This line of ViewController won't compile: [self setValue:offsetX forKeyPath:[NSString stringWithFormat:@"myView%d.center.x", anInt]]; but I can set ...

Parse Plist (NSString) into NSDictionary

So I have a plist structured string, that get dynamically (not from the file system). How would I convert this string to a NSDictionary. I've tried converting it NSData and then to a NSDictionary with NSPropertyListSerialization, but it returns "[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x100539f40" when I att...

Can you add a UITableViewController's TableView to another View?

I've inserted a UITableViewController and it's corresponding UITableView into a simple IB document. The goal is to include the UITableView inside of a parent UIWindow (or UIView) with other "stuff" (anything really) adorning the table. Here's what that might look like in Interface Builder. http://danharrelson.com/images/skitch/iphone-ta...

I have a circular reference. How can I create a weak reference in Objective-C?

I have an object of class Row that needs to release numerous objects of the class Block. Every Block currently has a property that retains an instance variable of class Row. Every Row contains an NSMutableArray of these Blocks. I understand that this is a circular reference. Apple's documentation states that in order to deallocate an obj...