objective-c

Fetching reference to superview from UITextField ?

Hi all, I have created three UIImageViews. I then added a UITextField to each image as a subview. When the user clicks on the text field I want to capture which UIImageView ths text field belongs to. I am trying the following code : -(void)textFieldDidBeginEditing : (UITextField *)textField { textField = retainedObject; MyPicture *...

Variable in a Variable iPhone?

Hi For my iPhone app in objective-c is it possible, and if so how can I make a variable inside a variable? For example, I have one named Var1 and then I can combine it with Var2. Lets say Var2 is a number, so it displays Var1 like Var11, the second one being Var2. Make sense? Anyway if Im not making sense, could you let me know how a v...

Cocos2d schedule method in NSObject

Hey Guys, It's me again with a Cocos2D problem. :-D I create the main character of my upcoming game as a sublclass of NSObject. This class has a property for the Sprite, Spritesheet and all that stuff. But now I have the following problem. I want to schedule a method for animating the sprite. That action which should be scheduled ever...

presentModalViewController desnt animate on iOS < 4.0

[self presentModalViewController:navController animated:YES]; I have scroll view with page control and paging enabled, each page has buttons who when pressed present modal view controller with additional data. when running on device with iOS 3.0->3.2 modal view controller on first page of scroll view animates properly (view scrolls ...

When to release a UIView that is removed from superview

I am creating a loading screen UIView which is added to a subview while some XML is parsed from some URL. Once the XML is returned, the loading screen is removed from its superview. The question I have is how should I release this object? In the code below, you'll see that I send removeFromSuperview to the loadingScreen, but I still h...

conflicting types for '-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row'

I have this code: - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { if ([[tableColumn identifier] isEqualToString:@"friend name"]) { if (row == 0) { return @"All friends"; } else { return [[friendsArray objectAtIndex:row - 1] name]; ...

can you return from a method early in an objective-c?

I'm doing some networking stuff in one of my methods and I would like the method to return NO and stop executing early if one of the internal calls returns an error, a bit like break for loops. Is this possible? IMO it would produce cleaner code rather than using a BOOL flag and having "should I continue executing this code?" if stateme...

Organize objective-C string for filters

How can I organize this string better for best coding practices. It's a string that defines filters: NSString* string3 = [[[[[[tvA.text stringByReplacingOccurrencesOfString:@"\n" withString:@" "] stringByReplacingOccurrencesOfString:@"&" withString:@"and"] stringByReplacingOccurrencesOfString:@"garçon" withString:@"garcon"] stringByRepl...

Drawing lat/lng points on an image

I have the following: An image - a hand drawn map - of an area of roughly 600x400 meters. The image is drawn on top of Google Maps tiles. The latitude/longitude (from Google Maps) of the corners of this image. Or put differently, I have the north and south latitude and the east and west longitude of the image. A latitude/longitude coor...

issue with StringByReplacingOccurrencesOfString options:NSCaseInsensitiveSearch

The options:NSCaseInsensitiveSearch is crashing my app when I have it in the following. Does anyone know why this might be? NSString* string3 = [[[[tvQ.text stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:NSCaseInsensitiveSearch range:wholeString] stringByReplacingOccurrencesOfString:@"&" withString:@"and"...

Cocoa get string width in pixels from font

Hey guys, I am trying to find the width in pixels of a string from the font and font size. I am currently using this code, but it is not working 100% of the time. Is there another way to do it? NSSize textSize = [aTextLayer.string sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:@"Bank Gothic Medium", NSFontNameAttribute, [...

Can you cast an NSString to an NSInterger? if the String contains numbers only?

I have some numbers stored in an NSString. Is it safe to extract them into an NSInterger like this : NSString* path = [[NSBundle mainBundle] pathForResource:@"rugby" ofType:@"txt" inDirectory:@""]; NSString* data = [NSString stringWithContentsOfFile:path encoding: NSUTF8StringEncoding error: NULL]; NSMutableArray *statsHolder = [[NSMut...

NSManagedObject relationships targeting classes that conform to a protocol

I have an Offer class (NSManagedObject subclass) that I want to use to handle offers made for purchases. One side of each offer is a buyer and the other side is the product. There is also a price. However these class instances that can be buyers have pretty different lineage and most likely will have different parent classes all the way ...

NSTimer crashes, when I call [Timer isValid] or [Timer invalidate]

Hi, I have two NSTimers in my iPhone app. DecreaseTimer works fine, but TimerCountSeconds crashes when I call [timerCountSeconds isValid] or [timerCountSeconds invalidate]. They are used like this: -(id)initialize { //Gets called, when the app launches and when a UIButton is pressed if ([timerCountSeconds isValid]) { [timerCountSecon...

Objective C try parse boolean

I would like to know how, in Objective-C, how to tell if a string represents a boolean value. The [string boolValue] method will not work, because when I try to parse a string like [@"ERROR" boolValue] it returns NO instead of throwing an exception. In C#, I could do something like: if (Boolean.TryParse(string, out bool)), but this is no...

Getting Current Directory in Objective C

I am trying to get current directory, but its giving me path of DEBUG folder, how i can get the path of current directory. I am using the following code. NSFileManager *filemgr; NSString *currentpath; filemgr = [[NSFileManager alloc] init]; currentpath = [filemgr currentDirectoryPath]; ...

Problems with getting glyph outline with appendBezierPathWithGlyphs

I'm working with Objective-C++. I'm trying to get the path outline of a text using NSBezierPaths appendBezierPathWithGlyphs. The problem is: the output is rather nonsense :( What I've written: String str = Ascii8("test string"); int length = str.getLength(); NSFont* font = [NSFont fontWithDescriptor: [NSFontDescriptor fontDesc...

File Handling in Objective C

Is there anyway to do Files Handling in Objective-C? I am just trying to do simple read and write and can use 'c' but i am force to use Objective-C classes for that :@. I am looking into NSInputStream, but its going over my head. Is there any tutorial which explains how to use NSInputStream? ...

iPhone SDK - Asynchronous Download Methods

Hello everyone, In Erica Sadun's Download Helper, link here, I can put these methods into my classes: - (void) didReceiveData: (NSData *) theData; - (void) didReceiveFilename: (NSString *) aName; - (void) dataDownloadFailed: (NSString *) reason; - (void) dataDownloadAtPercent: (NSNumber *) aPercent; these methods obviously refer back...

Image Sent via XML from iPhone to App Engine

I am trying to send a small image along with some XML information to App Engine from my iPhone app. I am having trouble with the image somewhere along the path. There is no error given and data is being transfered into a Blob entry in Datastore Viewer but the blob files on App Engine do not appear in Blob Viewer. I have a suspicion t...