遇到这个问题,是在实现一个公告栏界面的时候,公告栏可以新增一条公告,也可以删除一条公告。

新增很简单,这里不做多的介绍;

关于删除,之前的代码是:

GameObject go = is_parent.transform.FindChild(name).gameObject;
UIGrid grid = is_parent.GetComponent<UIGrid>();
Destroy(go);
grid.Reposition();

但是没有效果,选择任何排序模式都没效果。一直都是在grid中有一个  单元元素大小的 空缺位置。

随后百度n次之后,有人说使用 grid.repositionNow = true;

随后代码为:

GameObject go = is_parent.transform.FindChild(name).gameObject;
UIGrid grid = is_parent.GetComponent<UIGrid>();
Destroy(go);

grid.repositionNow = true;

依然无效,很是纠结。

最终一想,这里的销毁只是销毁当前 单元元素对象,并没有在grid中做处理,换而言之,grid中还是把这个删除的元素当做正常存在的元素在处理,有了这个想法之后,代码就成了现在这个样子:

GameObject go = is_parent.transform.FindChild(name).gameObject;
UIGrid grid = is_parent.GetComponent<UIGrid>();
grid.RemoveChild(go.transform);
Destroy(go);
grid.sorting = UIGrid.Sorting.Vertical;
grid.repositionNow = true;

先在grid中移除当前元素

再销毁这个元素

最后设置排序(在前面的几种方案中,设置排序是在面板上做的。)

最后刷新排序

OK!

到这里算是完整结束了,希望能帮助到遇到这个问题正在找方法的人。

有关ngui grid中去除一项后的排序问题的更多相关文章

  1. [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  2. [LeetCode] 26. Remove Duplicates from Sorted Array 有序数组中去除重复项

    Given a sorted array nums, remove the duplicates in-place such that each element appear only once an ...

  3. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项 II

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  4. 对Java数组中去除重复项程序分析

    我作为一个Java菜鸟,只会用简单的办法来处理这个问题.如果有大神看到,请略过,感激不尽! 所以首先先分析这道题目:数组中重复的数据进行删除,并且要让数组里的数据按原来的顺序排列,中间不能留空. 既然 ...

  5. [LeetCode] Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Follow up for "Remove Duplicates":What if duplicates are allowed at most twice? For exampl ...

  6. LeetCode 83. Remove Duplicates from Sorted List (从有序链表中去除重复项)

    Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...

  7. [LeetCode] 80. Remove Duplicates from Sorted Array II 有序数组中去除重复项之二

    Given a sorted array nums, remove the duplicates in-place such that duplicates appeared at most twic ...

  8. 关于layui中tablle 渲染数据后 sort排序问题

    最近在使用easyweb框架做后台管理,案例可见https://gitee.com/whvse/EasyWeb. 其中遇到了 sort排序问题, html代码:<table class=&quo ...

  9. [LeetCode] 26. Remove Duplicates from Sorted Array ☆(从有序数组中删除重复项)

    [LeetCode] Remove Duplicates from Sorted Array 有序数组中去除重复项 描述 Given a sorted array nums, remove the d ...

随机推荐

  1. Django的路由层详情

    1. Django的路由解析: 是从上往下进行匹配的 url(r'index', views.index) #这里的index 解析都可以被解析到的, abcindex index indexabc ...

  2. Cause: java.sql.SQLException: The user specified as a definer ('root'@'%') does not exist

    权限问题,授权 给 root 所有sql 权限 mysql> grant all privileges on *.* to root@"%" identified by &q ...

  3. 04_JSX练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Django 数据库的迁移

    先数据库迁移的两大命令: python manage.py makemigrations & python manage.py migrate 前者是将model层转为迁移文件migratio ...

  5. Django 之Form

    具体可参考:http://www.liujiangblog.com/course/django/153 https://www.cnblogs.com/liuguniang/p/7141837.htm ...

  6. Runloop原理

    简单的说,runloop是一个事件循环的机制,同时能够保活线程.iOS中每个线程都对应一个runloop,主线程的runloop默认开启,其他线程的runloop默认关闭,线程与runloop是一一对 ...

  7. 采用EntityFramework.Extended 对EF进行扩展

    今天我们来讲讲EntityFramework.Extended 首先科普一下这个EntityFramework.Extended是什么,如下: 这是一个对Entity Framework进行扩展的类库 ...

  8. Dev的TextEdit控件IP地址的Mask设置

    1. 添加TextEdit控件. 2. 选中TextEdit控件,查看控件属性. 3. 展开Properties属性项,找到Mask属性项. 4. 设置Mask属性项的EditMask属性值为:(25 ...

  9. 关于STRUCT优化的一个点

    在西山居的这篇U3D cheatsheet中,提到: c12. 确保 struct 实现了 Equals() 和 GetHashCode() 这怎么理解? 首先,看下system.object.equ ...

  10. .Net编译原理简单介绍

    首先简单说一下计算机软件运行.所谓软件运行,就是一步一步做一些事情.计算机只认识0和1.给计算机下命令,只能是0与1的方式,确切的说,其实是CPU只认识0和1,因为软件运行是CPU控制的.人直接操作0 ...