![](/img/trans.png)
[英]How to resize the row height of a UITableView automatically in xamarin ios
[英]Xamarin iOS UITableView, How to delete first row?
由于性能的原因,我在应用程序中实现了聊天功能,最多只能有100条消息,突然我发现,行编辑不是我所期望的那么容易。 所以我尝试了这个:
public void RemoveTopRow()
{
messages.RemoveAt (0);
tableView.ReloadData ();
}
但是它以本机异常崩溃了,我没有在这里停下来尝试这个:
tableView.DeleteRows (new NSIndexPath[]{ NSIndexPath.FromItemSection(0,0) }, UITableViewRowAnimation.Fade);
也许有人知道该怎么做? 我保证在下一个假期中,工作代码示例将非常有用,我保证,在下一个假期中,我将进行一些重构并将此聊天客户端发布在github上,这样其他人就可以在其项目中实现它而不会造成UI负担,因为我已经在这些布局修复上花了太多时间和精力
没有看到在哪里调用RemoveTopRow
方法,我只能猜测,但是从错误的角度来看,我假设您正在添加新的聊天行,并且正在从tableview / datasource之前的FIFO堆栈中删除第一个聊天行。完成同步:
public void RemoveTopRow()
{
dataSource.Objects.RemoveAt (0);
TableView.ReloadData ();
}
void AddNewItem (object sender, EventArgs args)
{
dataSource.Objects.Add (DateTime.Now);
// This will cause the error that you are seeing when
// it reaches the TableView.InsertRows...
//if (dataSource.Objects.Count > 10) {
// RemoveTopRow ();
//}
using (var indexPath = NSIndexPath.FromRowSection (0, 0))
TableView.InsertRows (new [] { indexPath }, UITableViewRowAnimation.Automatic);
//This will work
if (dataSource.Objects.Count > 10) {
RemoveTopRow ();
}
}
您需要在使用插入/删除之前调用BeginUpdates(),然后在之后调用EndUpdates()。 喜欢图片。 在此处输入图片说明
希望它能对您有所帮助。 关于Xamarin.iOS的任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.