Typical - in putting together a standalone code sample I realised the
mistake.
I was poking at the detail text label from outside the UITableView - and
GetCell was being called somewhere and regenerating fresh cells of course
without the detail text on them.
Below is the approach I am now using, which works fine.
namespace MyApp
{
using System;
using System.Collections.Generic;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
public class DemoViewController : UIViewController
{
UITableView table;
DemoSource src = new DemoSource();
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.table = new UITableView(new
RectangleF(0,0,320,460),
UITableViewStyle.Plain);
table.Source = src;
src.RowWasSelected += (ordinal) => {
src.SetDetailText(ordinal,
DateTime.Now.Ticks.ToString());
this.table.ReloadData();
};
this.View.AddSubview(this.table);
}
private class DemoSource : UITableViewSource
{
Dictionary<int, string> backing = new
Dictionary<int,
string>();
public Action<int> RowWasSelected;
public void SetDetailText(int ord, string text)
{
if (!backing.ContainsKey(ord))
{
backing.Add(ord, text);
}
else
{
backing[ord] = text;
}
}
public override int RowsInSection (UITableView
tableview, int section)
{
return 3;
}
public override UITableViewCell GetCell (UITableView
tableView,
MonoTouch.Foundation.NSIndexPath indexPath)
{
var cell = new
UITableViewCell(UITableViewCellStyle.Value1, "mycell");
cell.TextLabel.Text = "Cell " + (indexPath.Row
+ 1).ToString();
cell.DetailTextLabel.Text =
backing.ContainsKey(indexPath.Row) ?
backing[indexPath.Row] : "";
cell.Accessory =
UITableViewCellAccessory.DisclosureIndicator;
return cell;
}
public override void RowSelected (UITableView tableView,
MonoTouch.Foundation.NSIndexPath indexPath)
{
RowWasSelected(indexPath.Row);
tableView.DeselectRow(indexPath, true);
}
}
}
}
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/Problem-with-updating-UITableCell-s-DetailTextLabel-Text-tp3698301p3698393.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch