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

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

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

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. RabbitMq(2) 简单消息队列

    <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client </ar ...

  2. WIN10 常用bug解决办法

    1.没开始菜单,点不出来,无法关机 建立批处理,右键管理员运行. shutdown -s -t 0 2.没开始菜单,点不出来,无法重启 建立批处理,右键管理员运行. shutdown -r -t 0 ...

  3. Netty socket.io 启用Epoll 模式异常

    Epoll 环境为Linux 内核2.6 以上版本  Windows下不能启动 1:判断Linux环境 public static boolean isOSLinux() { Properties p ...

  4. Spring boot 错误处理机制

    请求方式时,若不存在 浏览器出现White label Error Page 错误页面 其他客户端出现响应一个JSON格式文本包含错误码等信息 浏览器发送请求的请求头: 客户端请求头 这样就能区分来自 ...

  5. 笨方法学python之读写文件、open函数的用法

    一.python读写文件相关知识点 close:关闭文件 read:读取文件的内容//你可以把结果赋给一个变量 readline:只读取文件中的一行 truncate 美 /trʌŋ'ket/ :清空 ...

  6. jquery下的正反选操作

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

  7. 尚硅谷springboot学习17-SpringBoot日志

    SpringBoot使用它来做日志功能: <dependency> <groupId>org.springframework.boot</groupId> < ...

  8. Constructor构造方法

    我们写一个car类,并写一个无参构造方法. public class Car { int speed; //构造方法名字和 类一致 区分大小写 不需要写返回值 和参数列表 public Car(){ ...

  9. asp.net 将文本转化为文本文件txt文件

    /// <summary> /// 将文本写入文本文件 /// </summary> /// <param name="name">完整文件名& ...

  10. swift 头尾式动画

    1.0 头尾式动画 UIView.beginAnimations(nil, context: nil) UIView.setAnimationDuration(1.0) // 设置执行动画所需要的时间 ...