objective-c

Settings IBOutlets to nil in dealloc

In the section titled 'Memory Warnings' here http://developer.apple.com/iphone/library/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmNibObjects.html, I don't follow why the IBOutlet is set to nil in the dealloc. If self.anOutlet = nil causes a crash as mentioned in the topic, why are they setting the ivar to nil? In general, ...

Webkit javascript evaluation uses different document object?

I'm hosting a webkit frame in my objective-C application and trying to execute some javascript on the loaded document using stringByEvaluatingJavaScriptFromString. Every call I make to document.getElementsByTagName('*') or document.getElementsByTagName('a') returns 0 length collections, regardless of the page I load in my webview. Othe...

Read NSNumber from NSData

Hi, I pretty new to Objective-C (and C itself) and need to consume a NSData from a HTTP output. I've never really worked with byte arrays or had to worry about little/big endian issues, and have struggled a bit to write the following method to read a NSNumber with a specified length from that NSData. - (NSNumber *)readNumberWithLength:...

Cocoa: Return to previous active application?

Hi, is there a way to capture application that was previously active, before my application was brought to front by user? I've tried to this in applicationWillBecomeActive: delegate method, but my application is already mark as active. Thanks. ...

How does presentModalViewController interact with nested UITabBarController and UINavigationController

I have a view that I want to take up the full screen, so I override the init method, and some of the view methods: - (id) init { if (self = [super init]) { self.wantsFullScreenLayout = YES; } return self; } - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[UIApplication sharedApplication] setStatu...

Removing url fragment from NSURL

I'm writing a Cocoa application, which uses NSURLs -- I need to remove the fragment portion of the URL (the #BLAH part). example: http://example.com/#blah should end up as http://example.com/ I found some code in WebCore that seems to do it by using CFURL functionality, but it never finds the fragment portion in the URL. I've encapsu...

how do we keep the keyboard rather than dismissing it using UITextField textFieldShouldReturn?

I want to keep my keyboard up after I input something since I am gathering up multiple answers for one question. So far I am calling: - (BOOL)textFieldShouldReturn:(UITextField*)textField { [textField resignFirstResponder]; return YES; } But when remove resignFirstResponder, I am not getting any response for my input handler on t...

sorting in nsmutable array

Suppose I have following data in my game. I have developed game in cocos2d. Name Score Sagar 10000 Amit 2000 Vishal 90 Above data is stored in plist file. Plist has an array as root. Within that there are 10 dictionary. Each dictionary has two values. String values - Name Number value - score When I use NSMutableArray...

Objective-C, sorting an array based on a objects instance variable.

I'm working on a game like Rodents Revenge, just to point out where I'm coming from with this question. I'm using the cocos2d game engine aswell... I have a layer that contains about 168 blocks, these blocks are a subclass of a Sprite. Each block contains two instance variables that are integers, one for the xGridLocation and yGridLocat...

On the iphone, how do I add a location to the maps application?

Is there a way to add a location from an MKMapView in my application to the built-in Google Maps app? From what I understand there is probably one of two ways to do it: using [[UIApplication sharedApplication] openURL:xxx] (like opening a web address, writing an email, or dialling a number) or using a C-api like adding a contact to the ...

Objective-C returning alloc'd memory in a function == bad?

This is on the iPhone. So what if I have a function like - (SomeObject*)buildObject; Do I need to pass in a variable that I have already alloc'd outside like - (void)assignObject(SomeObject** out); Or can I do - (SomeObject*)buildObject { return [[[SomeObject alloc] init] autorelease]; } and use it like SomeObject* obj = [[...

Creating public static constants in objective-c

I need to create static constants in a class that can be used by other classes that import that class. I'm assuming that enum would be the best way to go since I have seen it been used quite often through out Cocoa classes. ...

UIImage view questions

I have a UIImageview in my application and I was wondering how I can show an image in it pragmatically and change it whenever I want to! I think my major problem is exactly WHERE to put it! If you could show me what code and where that would be very usefull! thanks! EDIT: Also if you can pragmatically change the background into an image...

iPhone UIAlertView Problem

Ok so I have this code NSMutableArray *smartThings = [[NSMutableArray alloc] initWithCapacity:3]; NSMutableString *smartString = [NSString alloc]; int random; int numOfThings = 1; random = arc4random() % numOfThings; smartString = [smartThings objectAtIndex:random]; UIAlertView *smartAlert = [[UIAlertView alloc] initWithTitle:@"Thing To...

Getting Current Time in string in Custom format in objective c

I want current time in following format in a string. dd-mm-yyyy HH:MM How? Thanks in advance. Sagar ...

How can I set all cells in a tableView as checked or unchecked?

I have a checklist in a UITableView and I have a UISegmentedControl with "Select All" and "Deselect All" options. I am wondering how I can reset all the cells while viewing the table. The [self.tableView reloadData]; function does not seem to do the trick. Any thoughts? Thanks! ...

How to know a device's name from its device ID in OS X?

Hi all, I'm writing a program in OS X that receives click events from a mouse and a touchpad. When the user clicks at somewhere, the OS sends the device ID, which is just an int, and the position of the cursor to my callback function. I want to know if the click event comes from mouse or touchpad. So, how can I know the device's name fr...

String tokenizer in Objective-C for iPhone application development

I am writing a string tokenizer in Objective-C for an iPhone application. I have the result as: 1|101|Y|103|Y|105|Y|107|Y|109|Y|111|Y|113|Y|115|Y| I want to tokenize this string and display each of the values in tabular format. How am I to do it? I want the result in a tabular format. Like: 102 Y 103 Y .. ... ...

screen capture using objective c for mac

Does anyone has any idea how can I capture screen using objective c in mac os? to be more specific, how can I capture the active / focused application screen then create an image into a specified path. Any help is highly appreciated. ...

how to pass a string value from one view controller to another view controller

hi i am new to objective c. i have a login view controller with .h, .m, .xib files. and after successful login i need to go to the second page. The scenario is this, i am accessing web services. to authenticate the user, i send the username and password to the web service and in return i get a string value. based on the results of the...