views:

587

answers:

2

i wana store the index of seleted cell of table using NSArray, can u help me....

A: 

I don't know if I understand the question correctly, but it sounds like you could use a property list to store this information. Property lists are very easy to use and quite efficient with small amounts of data.

Read the "Property List Programming Guide" for further explanation. There is even a tutorial in there.

+1  A: 

You can use user defaults or property list for this.

Example on user defaults. You have a controller class that has access to the index and will load it at startup and write it into plist whenever it's updated:

If you have some kind of controller class then you would put this code into + (void)initialize, it initialises the variable if it does not exists in plist:

+ (void)initialize
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *appDefaults =
              [NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:5]
                                          forKey:@"MyFunnyIndex"];
    [defaults registerDefaults:appDefaults];
}

In your -(void)awakeFromNib (I'm assuming you're using some kind of controller class) load your last stored value:

-(void)awakeFromNib
{
    int index = 
           [[NSUserDefaults standardUserDefaults] integerForKey:@"MyFunnyIndex"];
           [somethingThatNeedsIndex setIndex:index];
    // ...
}

Somewhere where the index is updated (or where you want to write it to plist), let's call it - (void)updateInterface:

- (void)updateInterface
{
    [[NSUserDefaults standardUserDefaults]
                     setObject:[NSNumber numberWithInteger:index]
                        forKey:@"MyFunnyIndex"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}
stefanB