开发者

How to save Data in text file when user chooses a button

I开发者_开发百科 want to have user select between two different buttons on a view, If the the user selects the imageOne, a label is created called "imageOne", then I'll save the label into an array using the following technique:

- (IBAction)saveData {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *choice = [NSString stringWithFormat:@"%@/userschoice", documentsDirectory];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:imageOne.text];

    [array writeToFile:choice atomically:NO];
}

I'm trying to avoid using the Picker and a Tableview as I only have two choices and it will be easier for user to choose with a button. any guidance would be appreciated.

Thanks.

Michael


  1. Create the button, either in Interface Builder or in code
  2. Hook up the button's delegate to point to the controller
  3. Implement a method to do something in the controller (see link from number 2)
  4. Save data
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜