[MonoTouch] NSUserDefaults

Manoj Nagpal mjnagpal at gmail.com
Thu Oct 8 07:52:39 EDT 2009


Hi All,
has anyone used NSUserDefaults to save application settings ? I have been
looking for code samples without any avail.

I want to save the string value for the Settings View. This doesn't seem to
be working. This is what I am trying:

To Save the value:
public override void EditingEnded (UITextField textField)
{

var prefs = NSUserDefaults.StandardUserDefaults;

  switch (textField.Tag)
  {
   case 0:
prefs["LastName"] = textField.Text;
break;
...

and to retrieve it:
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath
indexPath)
{
...
var prefs = NSUserDefaults.StandardUserDefaults;
...
if (row == 0)
{
cell.TextLabel.Text = "Last Name";
string obj = Convert.ToString(prefs["LastName"]);
if (obj == null)
obj = "";
cell.ContentView.AddSubview (TextFieldNormal("your last name", obj, 1,
UIKeyboardType.Default));
}
...

Please help.

Cheers
Manoj.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20091008/54f5a9f6/attachment.html 


More information about the MonoTouch mailing list