elez
elez

Reputation: 55

How can i pass values from view controller class to objective c class with UIView as subclass in iPad

I want to pass values(inputs from user)from view controller class to objective c class with UIView as subclass.And in objective c class I want to draw using these inputs. how an I do it? Please help me?

Upvotes: 2

Views: 249

Answers (1)

PengOne
PengOne

Reputation: 48406

If the input is an int, float, BOOL, NSString, NSData or NSDate, then the easiest thing to do is to store these values in NSUserDefaults. They can then be recalled any time you wish from any UIViewController.

The NSUserDefaults Class Reference has all the information to get you started. In addition to the wealth of information there, here's a simple example of how to save and retrieve an NSString:

-(void)saveToUserDefaults:(NSString*)myString
{
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

    if (standardUserDefaults) {
        [standardUserDefaults setObject:myString forKey:@"Prefs"];
        [standardUserDefaults synchronize];
    }
}

-(NSString*)retrieveFromUserDefaults
{
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    NSString *val = nil;

    if (standardUserDefaults) 
        val = [standardUserDefaults objectForKey:@"Prefs"];

    return val;
}

Upvotes: 1

Related Questions