专家,删除行数据源问题 - 无效更新:行数无效在第0与Xamarin.iOS
我有一个从一个JSON文件中的一些细胞填充一个UITableView。我希望用户轻扫以删除特定的单元格。我使用SWTableViewCell组件实现了删除功能,并且几乎让它解决了一个问题:“无效更新:节0中的行数无效”。我怀疑我需要从我的模型中的数据源和我的JSON文件中删除对象,但不知道如何去做。提前致谢!
下面是执行:
public override void DidTriggerLeftUtilityButton(SWTableViewCell cell, nint index)
{
// Delete button was pressed
switch (index)
{
case 0:
NSIndexPath cellIndexPath = tableView1.IndexPathForCell(cell);
dataList.RemoveAt(cellIndexPath.Row);
tableView1.DeleteRows(new[] { cellIndexPath }, UITableViewRowAnimation.Left);
break;
}
}
public override nint RowsInSection(UITableView tableview, nint section)
{
return dataList.Count;
}
这里是填充JSON模式:
public class DataLocalNotifications
{
public string name { get; set; }
public string NotificationMessage { get; set; }
public string date { get; set; }
public string logo { get; set; }
public double latitude { get; set;}
public double longitude { get; set;}
public string website { get; set; }
public double phone { get; set; }
public string yelp { get; set; }
public DataLocalNotifications()
{
}
}
public class LocalNotificationsModel
{
List<DataLocalNotifications> _model = new List<DataLocalNotifications>();
public List<LocalNotificationsModel> businessList = new List<LocalNotificationsModel>();
public static LocationManager Manager { get; set; }
public double distance;
CLLocationManager location;
public double Lat { get; set; }
public double Long { get; set; }
public DataLocalNotifications this[int index]
{
get { return _model[index]; }
set { _model[index] = value; }
}
public List<DataLocalNotifications> data
{
get { return _model; }
set { _model = value; }
}
public int Count
{
get { return _model.Count; }
}
public void Add(DataLocalNotifications item)
{
_model.Add(item);
}
public static LocalNotificationsModel Init()
{
LocalNotificationsModel model = new LocalNotificationsModel();
string documentsPath1 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var localPath1 = Path.Combine(documentsPath1, "Notifications.json");
var project1= JsonConvert.DeserializeObject<RootObjectNotifications> (System.IO.File.ReadAllText (localPath1));
//project1.Notifications.Reverse();
foreach (var bus in project1.Notifications.OrderByDescending(x => x.UnixTime))
{
model.Add(new DataLocalNotifications
{
NotificationMessage = bus.BusinessNotification,
name = bus.Name_Location,
date = bus.Date,
logo = bus.BusinessImage,
latitude = bus.Latitude,
longitude = bus.Longitude,
website = bus.Website,
phone = bus.Phone,
yelp = bus.Yelp
});
}
return model;
}
为什么不使用STANDAR滑动删除? – XTL
标准滑动删除,我会得到相同的结果。我使用该组件的优点很多。 – pkozlowski
嗯..我可以展示如何通过本地的东西(没有组件)来实现它。如果你愿意,我会提供样品。 – XTL