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

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

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

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. ASP.NET前台代码绑定后台变量方法总结

    经常会碰到在前台代码中要使用(或绑定)后台代码中变量值的问题.一般有<%= str%>和<%# str %>两种方式,这里简单总结一下.如有错误或异议之处,敬请各位指教. 一方 ...

  2. leetcode985

    import sys class Solution: def sumEvenAfterQueries(self, A: 'List[int]', queries: 'List[List[int]]') ...

  3. MVC基于角色权限控制--数据库设计

    在网站后台设计过程中都会遇上权限控制这一问题 当前较为流行的解决方案是基于角色的权限管理 基本思路如下 分别建立 用户信息表.角色信息表.权限信息表 让用户和角色关联,角色和权限关联,当用户访问时,通 ...

  4. 初识web.xml文件

    做了那么久的web项目都没有花心思了充分解下这个文件有什么用,看项目配制是否都差不多呢 ======================================================== ...

  5. Servlet基本_サーブレットのライフサイクル、スレッドセーフ

    1.サーブレットのライフサイクル初期化時 ⇒ init() [初回リクエスト時] ↓リクエスト時 ⇒service() ⇒doGet() [Httpリクエストメソッドにより振り分け] 或は⇒doPos ...

  6. AWK 知识库

    awk 极客课程 <AWK 编程语言>1 <AWK 编程语言>2 <AWK程序设计语言>https://github.com/wuzhouhui/awk http: ...

  7. NetStream 记录

    bufferLength : Number [只读] 数据当前存在于缓冲区中的秒数.(已进入缓冲区的秒数) bufferTime : Number 指定在开始显示流之前需要多长时间将消息存入缓冲区.( ...

  8. java字符串格式化:String.format()方法的使用

    转自:http://kgd1120.iteye.com/blog/1293633 常规类型的格式化 String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的读者应 ...

  9. Servlet之ServletContext获取web上下文路径、全局参数、和Attribute(域)

    1)获取web上下文路径 public void doGet(HttpServletRequest request, HttpServletResponse response) throws Serv ...

  10. 如何遍历Set对象

    对 set 的遍历 1.迭代遍历: Set<String> set = new HashSet<String>(); Iterator<String> it = s ...