我有代码,所以当我点击“=”以使用“Chord方法”
找到解决方案时如何制作,以便结果显示在标签中控制台 ??
var resultsArray = [AnyObject]()
var a: Float = 0.0
var b: Float = 0.0
var xNext: Float = 0
var nextFunc: Float = 3
var funcB: Float = 0
var iter: Int = 0
var result = ""
@IBOutlet weak var aInput: UITextField!
@IBOutlet weak var bInput: UITextField!
@IBOutlet weak var resultLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
resultsArray.removeAll()
iter = 0
a = Float(aInput.text!)!
b = Float(bInput.text!)!
funcB = pow(b, 3)-b-1
nextFunc = pow(a, 3)-a-1
xNext = a
while (-0.001..<0.001).contains(nextFunc) != true{
xNext = xNext - ((b - xNext)/(funcB - nextFunc)) * nextFunc
nextFunc = pow(xNext, 3) - xNext - 1
iter+=1
resultLabel.text = "x\(iter) = \(xNext) \nF(x\(iter)) = \(nextFunc)\n"
print ("x\(iter) = \(xNext) \nF(x\(iter)) = \(nextFunc)\n")
resultsArray.append(resultLabel as AnyObject)
}
view.endEditing (true)
}
答案 0 :(得分:1)
由于@Bean
@ServiceActivator(inputChannel = "sftpChannel")
public MessageHandler handler() {
final FileWritingMessageHandler handler = new FileWritingMessageHandler(new File(OUTPUT_DIR));
handler.setFileExistsMode(FileExistsMode.REPLACE);
handler.setExpectReply(true);
handler.setOutputChannelName("parse-csv-channel");
return handler;
}
@ServiceActivator(inputChannel = "parse-csv-channel", outputChannel = "job-channel")
public JobLaunchRequest adapt(final File file) throws Exception {
final JobParameters jobParameters = new JobParametersBuilder().addString(
"input.file", file.getAbsolutePath()).toJobParameters();
return new JobLaunchRequest(batchConfiguration.job(), jobParameters);
}
@Bean
@ServiceActivator(inputChannel = "job-channel")
public JobLaunchingGateway jobHandler() {
JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(jobLauncher);
jobLaunchingGateway.setOutputChannelName("finish");
return jobLaunchingGateway;
}
是引用类型对象,因此您的代码不会向数组中添加新标签,而只是反复添加相同的标签(并覆盖它的文本)。
由于我假设您要将结果添加到UILabel
,因此您首先需要将UITableView
更改为resultsArray
而不是[String]()
。
然后你可以适应
[AnyObject]()
到
resultLabel.text = "x\(iter) = \(xNext) \nF(x\(iter)) = \(nextFunc)\n"
print ("x\(iter) = \(xNext) \nF(x\(iter)) = \(nextFunc)\n")
resultsArray.append(resultLabel as AnyObject)
现在,最后一步是让 let result = "x\(iter) = \(xNext) \nF(x\(iter)) = \(nextFunc)\n"
resultsArray.append(result)
tableView.reloadData()
符合它的委托并添加委托方法。为简单起见,这使用默认的iOS TableViewCell,但如果需要,可以根据自定义单元格进行调整。
在tableView
viewDidLoad()
添加以下代理(记得将MyViewController更改为ViewController的名称)
tableView.delegate = self
tableView.dataSource = self