objective-c

can i add an ivar (or property) to an existing class in objective-c?

I'm wondering if it's possible to add an ivar to the UIButton class? A bit like categories but not for a method(s) but for ivars. I am programmatically creating and displaying an array of UIButton's which I then all link up to a single action method using –addTarget:action:forControlEvents: for a touchup event. Now, my receiver method ...

Compress this into a function?

Hi I have the following code which is really long of course, how can I compress this into a function? Then call this function with the other weekdays and lessons in the week? Currently Im just using the same code over and over just replacing the variables (which are strings). //Allocate and add objects to monday week one. monArrayA ...

How to check if a specific UIViewController's view is currently visible?

I'm developing an app that processes a constant stream of incoming data from the network and provides a number of different UIViews for the user to view that data. When certain model data gets updated based on the incoming stream from the network, I access the associated UIViewController or UITableViewController and do -setNeedsDisplay ...

Routing iPhone Audio Sound

I have an app which does listen and play sound at the same time. By default, the sound output goes through the earphone. So I use the following code to route it through the speaker: UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker; AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof(audioRouteOve...

centering a CGRect in a view

I have an image displaying in a CGRect. how do I center the rect in the view? here's my code: UIImage * image = [UIImage imageNamed:place.image]; CGRect rect = CGRectMake(10.0f, 90.0f, image.size.width, image.size.height); UIImageView * imageView = [[UIImageView alloc] initWithFrame:rect]; [imageView setImage:image]; I've tried imag...

VPN connection with Objective-C

Hi Developers! Is there a way to establish a VPN connection programmatically in Objectiv-C for the iPhone? Are there somewhere good tutorials for this? Does anyone know? Thanks Taimur ...

Try-catch exception handling practice for iPhone/Objective-C

Hi all, Apologies if this question has already been answered somewhere else, but I could not find any decisive answer when searching on it: I'm wondering when try-catch blocks are to be used in objective-c iPhone applications. Apple's "Introduction to the Objective-C Programming Language" state that exceptions are resource intensive an...

UIView background color not set until device rotates

I'm working with a simple iPad application, and I've got a simple problem. I'm setting up a custom UIView; here's my initWithFrame: - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { self.backgroundColor = [UIColor colorWithWhite:.4 alpha:1.0]; .... } return self; } The ...

Set Multiple Variables to Same Value

Hi I have dozens of NSStrimgs that when the app loads I want to all be set to the same set. All of them. How can I do this without typing out every single one? Is there a shortcut method? Thanks. ...

Categories and instance variables

I am attempting to add a category to NSMutableArray to allow me to use it as a 2D array (backed by the 1D array, with a method to convert x & y indexes into a flat index). As I am not allowed to add instance variables to a category, how should I keep track of row and column counts which are required to calculate the index into the array?...

Cursor position in a UITextView.

I am looking for a non private way to find the position of the Cursor or Caret (blinking bar) in a UITextView preferably as a CGPoint. There may be a question like this already but it does not provide a definitive way for doing it. And, I do not mean the NSRange of the selected area. ...

Making a custom Button using a UIView or overriding UIButton?

Hi guys, I need to generate a custom button through code, this is how i am currently doing it. -(void) initialiseButtons { int ypos = playerImage.frame.origin.y + playerImage.frame.size.height + 8; for(int i=0; i<totalButtons; i++) { UIButton *newButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; ...

objective-c memory management

Hi guys, i have some questions about objective-c's memory management, let's say: NSString * test= [[NSString alloc] init ] test=@"msg"; [object setStr1: test ]; // declared as: @property(copy, readwrite) [object setStr2: test ]; // declared as: @property(retain, readwrite) [object setStr3: test ]; // declared as: @property(assign,...

UiView fadeOut if not touched

I'd like to reproduce this behavior in my iPad application. I have a subView that contains four custom buttons. The view has an alpha value of 0.0 I have another custom button outside of the view descripted above that is always visible. When the user touches the visible button the view appear animating its alpha to 1.0 showing the othe...

delete string content

i fill a string with coordinates , thats working fine. but how can i delete the content of this string. PS: i use this string in a web services. the web services takes the string and convert it in the typ double. if i make lat = nil; it dosent work. here the code: double degreesLat = newLocation.coordinate.latitude; lat = [NSStri...

How to init NSObject<protocol> pointer so it responds to delegate SEL?

I have such thing in my class definition: NSObject<SomeProtocol> *dataDelegate; I have custom -(id)init method in which I should init this NSObject. How do I do it if I want it to respond selectors from SomeProtocol? ...

What type should alloc return?

I have a method like this which performs further initializations on other objects with similar init methods. - (Foo*)initWithInput:(NSMutableString*)i { bar = [[Bar alloc] initWithInput:input]; return self; } This produces a warning "Foo.m:19: warning: incompatible Objective-C types assigning 'struct Foo *', expected 'struct Bar *...

iPhone objective-c wifi spots list

Hi everyone, I've got a question about iPhone developing. Is there a example code or tutorial for getting a list or maybe an array with wifi spots that where find in the current environment? Thanks a lot! :) ...

Setting a prompt in an ABPeoplePickerNavigationController

I'm having trouble getting this code to set the prompt: // Create a PeoplePicker ABPeoplePickerNavigationController *objPeoplePicker = [[ABPeoplePickerNavigationController alloc] init]; [objPeoplePicker setPeoplePickerDelegate:self]; // Customize colors objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [U...

Core Data - Basic Questions

Hello, I would like to know how the following works in Objective-C in my header file i have the following which is initialized from a different view controller @interface UserLookup : UIViewController { NSManagedObjectContext *referringObject; } and in my implementation file i have to pass this NSManagedObjectContext to 2 chil...