小编Jer*_*Rea的帖子

Swift代表没有被调用

我有一个代表的视图,我希望在按下按钮时在GameController中调用numpadView(numpadView :),但是我无法让它工作.touchesBegan()的重载工作正常,它实际上是使用pressDelegate?.numpadView(self)的行,它不会调用GameController类中的委托函数.为了让它起作用,我很遗憾失去了什么?

为了简单起见,我清理了代码,只留下与问题相关的基本内容.

NumpadView.swift

protocol NumpadPressDelegateProtocol {
  func numpadView(numpadView: NumpadView)
}

class NumpadView: UIButton{
  var pressDelegate: NumpadPressDelegateProtocol?

  init(char: Character) {
    let frame = CGRectMake(160, 100, 50, 50)
    super.init(frame:frame)

    self.setTitle("\(char)", forState: UIControlState.Normal)
    self.userInteractionEnabled = true
  }

  override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    pressDelegate?.numpadView(self)
  } 
}
Run Code Online (Sandbox Code Playgroud)

GameController.swift

class GameController: NumpadPressDelegateProtocol {

  func numpadView(numpadView: NumpadView) {
    //do something
  }

}
Run Code Online (Sandbox Code Playgroud)

uikit ios swift

13
推荐指数
1
解决办法
1万
查看次数

如何从jt中具有多对多关系的jointable中删除记录

删除条目时,我收到约束违规异常

我有关系表TransportationEvent和结论

关系就像

@Entity
public class TransportationEvent {

...

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST)
    private List<Conclusion> conclusions = new ArrayList<Conclusion>();

...

}

@Entity
public class Conclusion {

....

@ManyToMany( fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
    private List<TransportationEvent> transportationEvents = new ArrayList<TransportationEvent>();

....

}
Run Code Online (Sandbox Code Playgroud)

在数据库中,我有另外两个表

结论_TransportationEvent和TransportationEvent_Conclusion

这里我的要求是我需要删除两个表中的记录(TransportationEvent和结论)

在这里,我试图删除如下的结论表记录:

removeConclusions(conclusion.getId());

 public void removeConclusions(Long id) {
        entityManager = dbConn.getConnection();
        Conclusion conclusion = entityManager.find(Conclusion.class, id);
        entityManager.getTransaction().begin();
        entityManager.remove(conclusion);
        entityManager.getTransaction().commit();
}
Run Code Online (Sandbox Code Playgroud)

但我得到约束违规错误.

引发者:java.sql.SQLException:DELETE语句与REFERENCE约束"FK30CDAB072AAE439"冲突.冲突发生在数据库"ECT",表"dbo.TransportationEvent_Conclusion",列'ending_id'

通过搜索一些论坛,我得到了语法

@Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
Run Code Online (Sandbox Code Playgroud)

我把它应用为

@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.REMOVE})
    @Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    private …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa jpa-2.0

4
推荐指数
1
解决办法
6528
查看次数

循环python"if"语句

我正在构建一种问题序列作为Python 3.2中程序的一部分.基本上,我提出一个问题并等待两种可能性之间的答案.如果给定的答案不是两个选项的一部分,我打印一行,并希望重新问问题,直到给出正确的输入,然后继续下一个问题并重复相同的顺序.

这里有一段代码可能更好地解释自己:

colour = input("black or white?")
if colour in ["black", "white"]:
    print("Thank you")
else:
    print("Please choose one or the other")
Run Code Online (Sandbox Code Playgroud)

换句话说,如果给定的答案不是黑色或白色,我想打印"请选择一个或另一个",并重新提出问题,只要没有给出黑色或白色.一旦给出黑色或白色,我希望它突破if语句,以便我可以用同样的方式提出另一个问题.

我已经搜索了如何做到这一点,但没有找到任何有用的东西.我猜一个循环,但是当我尝试它时,只是无限地吐出我最后一个打印字符串.

python loops if-statement python-3.x

-1
推荐指数
2
解决办法
451
查看次数

标签 统计

hibernate ×1

if-statement ×1

ios ×1

jpa ×1

jpa-2.0 ×1

loops ×1

python ×1

python-3.x ×1

swift ×1

uikit ×1