我在一个aspnet_regsql -d SessionStateDb -ssadd -S msserver -U sa -P 1 -sstype c
中有一个UIButton
。我使用自定义委托打印文本。现在,问题是委托方法在UIViewController
时没有在理想情况下执行。(即,像viewDidAppear(animated)
)
协定:
UITableViewDataSource
水果类
protocol FruitDelegate{
func fruit(_ name:String,taste:String)->Bool
}
查看控制器:
class Fruit{
var delegate:FruitDelegate?
var name:String!
var taste:String!
init(name:String,taste:String){
self.name = name
self.taste = taste
}
func isTrue(){
if self.delegate?.fruit(name, taste: taste) == true{
print("Answer Correct")
}else{
print("Answer Wrong")
}
}
}
我知道下面的代码会为我提供问题的确切解决方案。
class ViewController: UIViewController,FruitDelegate {
@IBOutlet var textLabel: UILabel!
let fruit = Fruit(name: "mango", taste: "sweet")
override func viewDidLoad() {
super.viewDidLoad()
self.fruit.delegate = self
}
func fruit(_ name: String, taste: String) -> Bool {
if name == "mango" && taste == "sweet"{
return true
}else{
return false
}
}
@IBAction func actionRefreshButton(_ sender: UIButton) {
self.fruit.isTrue()
}
}
但是,是否有必要在override func viewDidLoad() {
super.viewDidLoad()
self.fruit.delegate = self
self.fruit.isTrue()
}
方法上调用self.fruit.isTrue()
? (最多viewController
)。在viewDidAppear
中,当出现视图时,无需在理想情况下调用UITableView
。同样,我需要执行reloadData()
方法。我怎么办?
答案 0 :(得分:2)
您只需在代理人 <script type="text/javascript">
$(function() {
$('#product-table').DataTable({
processing: true,
serverSide: true,
ajax: '{{ url('product/get_product_datatable') }}',
columns : [
{data: 'id', name: 'id'},
{data: 'product_code', name: 'product_code'},
{data: 'action', searchable: false, orderable: false},
{data: 'add_price', searchable: false, orderable: false},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
]
});
});
</script>
中调用isTrue
方法
didSet