我的第一个iOS应用程序(实用程序)发布即将完成,但仍然存在一个问题:应用程序运行自动序列.在大多数其他平台上,序列将完成/失败/取消,然后是清理和退出(x).
我意识到我的iOSapp不应该退出(),所以它返回到执行清理的UIApplicationDelegate; 将所有控制器设置为nil(使用ARC),只保留appDelegate实例.然后应用程序应该重新启动初始视图控制器,有效地再次启动应用程序.
来自UIApplicationDelegate的电话是做什么的?我希望它应该与iOS在初始故事板应用启动时调用的相同.
在重构 Java 项目以使用组合而不是继承时,我仍然存在执行集合的多态排序的问题。
继承示例:
public class AClass
{
private List<OneClassOfManyThatRequireSortedInstances> unsortedList;
public List<OneClassOfManyThatRequireSortedInstances> getSortedList()
{
List<OneClassOfManyThatRequireSortedInstances> sortedList = new ArrayList(this.unsortedList);
Collections.sort(sortedList, SuperClassOfManyThatRequireSortedInstances.orderComparator);
return sortedList;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,经过重构;类OneClassOfManyThatRequireSortedInstances不再从抽象继承,SuperClassOfManyThatRequireSortedInstances而是Collections.sort()期望相互比较的实例。
重构它的最佳方法是什么?
为了完整性;我添加了 Comparator 实现并进一步说明了问题。
public class SuperClassOfManyThatRequireSortedInstances
{
private int order;
public static final Comparator<SuperClassOfManyThatRequireSortedInstances> orderComparator = new Comparator<SuperClassOfManyThatRequireSortedInstances>()
{
public int compare(SuperClassOfManyThatRequireSortedInstances o1, SuperClassOfManyThatRequireSortedInstances o2)
{
if ((o1 == null) && (o2 == null))
{
return 0;
}
if (o1 == null)
{
return -1; …Run Code Online (Sandbox Code Playgroud)