我正在使用TapGestureRecognizer创建一个具有可变数量视图的应用程序.按下视图时,我目前正在执行此操作
func addView(headline: String) {
// ...
let theHeadline = headline
let tapRecognizer = UITapGestureRecognizer(target: self, action: Selector("handleTap:"))
// ....
}
Run Code Online (Sandbox Code Playgroud)
但在我的函数"handleTap"中,我想给它一个额外的参数(而不仅仅是发送者),就像这样
func handleTap(sender: UITapGestureRecognizer? = nil, headline: String) {
}
Run Code Online (Sandbox Code Playgroud)
如何将特定标题(每个视图都是唯一的)作为handleTap函数的参数发送?
我正在制作一个集合视图,并制作了我自己的自定义collectionCell.我已在身份检查员中指明了这一点,据我所知,我做的一切都是正确的.
代码是
import UIKit
class SubjectCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var label: UILabel!
}
Run Code Online (Sandbox Code Playgroud)
并在我的collectionViewController中
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! SubjectCollectionViewCell
return cell
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息
"无法将'UICollectionViewCell'类型的值(0x110460820)转换为'project.SubjectCollectionViewCell'(0x10eceeda0).(lldb)"
我的目标是能够使用 Multer 将图像上传到 mongoDB Atlas。目前,我已经使用express-generator设置了一个示例,其中包含以下相关文件:
应用程序.js:
// ...
var app = express();
//Set up mongoose connection
var mongoose = require('mongoose');
var mongoDB = 'mongodb+srv://username:password@cluster0-wczgu.mongodb.net/test?retryWrites=true&w=majority';
mongoose.connect(mongoDB, { useNewUrlParser: true });
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
// ...
Run Code Online (Sandbox Code Playgroud)
索引.js:
var express = require('express');
var router = express.Router();
var multer = require("multer");
var fs = require("fs");
var upload = multer({ dest: 'uploads/' })
var Image = require('../models/image');
// GET for image form
router.get("/image/create", function(req, res, next) {
res.render("create_image", {title: …Run Code Online (Sandbox Code Playgroud) 我的课程类似于下面的课程.它是简化的,但它说明了我的问题.我想用"square"函数初始化"number"变量.
class SomeClass {
let number: Int
func square (num: Int) -> Int {
return num * num
}
init(num: Int) {
number = square(num)
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我创建一个类的实例时.例如
let instance = SomeClass(num: 2)
Run Code Online (Sandbox Code Playgroud)
它抛出错误:在初始化所有存储的属性之前,在方法调用'square'中使用'self'.
如何使用该函数初始化数字?