Tag: objective c

how to prevent NSJSONSerialization from adding extra escapes in URL

How do I prevent NSJSONSerialization from adding extra backslashes to my URL strings? NSDictionary *info = @{@”myURL”:@”http://www.example.com/test”}; NSData data = [NSJSONSerialization dataWithJSONObject:info options:0 error:NULL]; NSString *string = [[NSString alloc] initWithData:policyData encoding:NSUTF8StringEncoding]; NSLog(@”%@”, string);//{“myURL”:”http:\/\/www.example.com\/test”} I can strip the backslashes and use that string but I would like to skip that step if possible…

Uploading Image via POST in Objective C

I’m currently working on uploading an image to a server via HTTP Post and can’t seem to figure out a way to build the url that calls the service. The user selects an image from the library or camera and then calls a json service that performs the insert statement. The service is expecting the […]

Responding to touchesBegan in UIPickerView instead of UIView

I have a UIPickerView that gets faded out to 20% alpha when not in use. I want the user to be able to touch the picker and have it fade back in. I can get it to work if I put a touchesBegan method on the main View, but this only works when the user […]

How to make a superview intercept button touch events?

Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { // How can I get this to show up even when the button is touched? NSLog(@”%@”, [touches anyObject]); } @end @interface TestViewAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; } @end @implementation TestViewAppDelegate – (void)applicationDidFinishLaunching:(UIApplication *)application […]

How do I parse an NSString containing XML in Objective-C?

In my iPhone application, I have the following NSString: NSString *myxml=@”<students> <student><name>Raju</name><age>25</age><address>abcd</address> </student></students>”; How would I parse the XML content of this string?

Can I disable UIPickerView scroll sound?

I want to disable the annoying clicks that the UIPickerView generates upon scrolling up and down. Is there a way to do this? I want to play short sounds for each item that the picker view lands upon. It gets ruined by the built in sound. I understand that the picker sounds can be turned […]

Hide autolayout UIView : How to get existing NSLayoutConstraint to update this one

I know how to modify a existing constraint. But I would to know if someone has found a solution to get a constraint without save this one as a property. Current solution to set Constraint height: 1) save NSLayoutConstraint in a variable: NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:myView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:20]; [self.view addConstraint:heightConstraint]; […]

Objective-C call function on another class?

Here are my objective-c classes: AppDelegate SomeScript How might I call the function loggedIn on the SomeScript class from the app-delegate or any other class? Thanks, Christian Stewart

What's the best way to use Obj-C 2.0 Properties with mutable objects, such as NSMutableArray?

I have an Obj-C 2.0 class that has an NSMutableArray property. If I use the following code, then the synthesised setter will give me an immutable copy, not a mutable one: @property (readwrite, copy) NSMutableArray *myArray; Is there any reason that Apple didn’t implement the following syntax? @property (readwrite, mutablecopy) NSMutableArray *myArray; Since we don’t […]

Formatting a number to show commas and/or dollar sign

I want to format my UILabel with commas or better with a dollar sign and commas (with no decimal). Here is the code I am using: IBOutlet UILabel *labelrev float rev = (x + y) labelrev.text = [[NSString alloc] initWithFormat:@%2.f”,rev]; I get xxxxxxxxx as the output I want to get xxx,xxx,xxx or $xxx,xxx,xxx How do […]