我正在从URL读取json,并且(我在ObjectiveC中遇到了同样的问题)这些值会导致我的应用程序崩溃.我对字符串和数字没有任何问题.我可以println(值)但是当我将值分配给UILabel时,它会崩溃.
我用这个方法来读取JSON:
func jsonFromURL(jsonURL: String) -> Dictionary<String, AnyObject> {
var jsonNSURL: NSURL = NSURL(string: jsonURL)
let jsonSource: NSData = NSData(contentsOfURL: jsonNSURL)
var json = NSJSONSerialization.JSONObjectWithData(jsonSource, options:NSJSONReadingOptions.MutableContainers, error: nil) as Dictionary<String, AnyObject>
return json
}
Run Code Online (Sandbox Code Playgroud)
...以及此代码将值分配给自定义Cell中的UILabel
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
var regularTextCell:celda = celda(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
var cell:celda = NSBundle.mainBundle().loadNibNamed("celda", owner: self, options: nil)[0] as celda
cell.name.text = myJson["list"]![indexPath.row]!["name"] as String
cell.id.text = "id: " + String(myJson["list"]![indexPath.row]!["id"] as Int)
// THIS line crash because some …Run Code Online (Sandbox Code Playgroud) 在电子应用程序中操作 DOM 的最佳方法是什么?
我使用 ipc 和 webcontents 从文档中制作了一些教程,但没有运气
我的应用程序非常简单,我只想像控制台一样使用网络并显示来自多个同步函数(主过程)结果的消息(渲染过程)
我用真实的代码更新了这个问题。
我要放另一个代码,更容易看,更容易测试(我认为),是真正的代码和工作(但不是我想要的)
当我启动电子时,只写最后一条消息。好的,响应真的很快,我可能看不到第一条消息,但我放弃了我也放了一个 setTimeout 和一个大的 for() 循环,以使大写函数需要更长的时间
索引.js
const electron = require('electron');
const {app} = electron;
const {BrowserWindow} = electron;
const ipc = require('electron').ipcMain
app.on('ready', () => {
let win = new BrowserWindow({width: 800, height: 500});
win.loadURL('file://' + __dirname + '/index.html');
// Emitted when the window is closed.
win.on('closed', () => {
win = null;
});
// Event that return the arg in uppercase
ipc.on('uppercase', function (event, arg) {
event.returnValue = …Run Code Online (Sandbox Code Playgroud)