小编The*_*ow_的帖子

Symfony 2:上传文件并保存为blob

我正在尝试使用表单和Doctrine在数据库中保存图像.在我的实体中,我做到了这一点:

/**
 * @ORM\Column(name="photo", type="blob", nullable=true)
 */
private $photo;

private $file;


/**
 * @ORM\PrePersist()
 * @ORM\PreUpdate()
 */
public function upload()
{
    if (null === $this->file) {
        return;
    }

    $this->setPhoto(file_get_contents($this->getFile()));
}
Run Code Online (Sandbox Code Playgroud)

我还在我的表单类型中添加了这个:

->add('file', 'file')
Run Code Online (Sandbox Code Playgroud)

但是当我上传文件时,我收到此错误:

不允许序列化'Symfony\Component\HttpFoundation\File\UploadedFile'

php doctrine blob symfony

9
推荐指数
1
解决办法
8299
查看次数

iOS:tableView.reloadData()在swift中不起作用

我正在尝试在更新Swift中的数据后重新加载我的表视图,但它似乎不起作用.当我更改选项卡并返回时,表视图会重新加载但不会自动重新加载.这是我的代码:

override func viewDidLoad() {
    super.viewDidLoad()

    // some code

    refresh(self)
}

func refresh(sender: AnyObject) {
    // Reload the data

    self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么它在Objective-C中工作但在Swift中不起作用...我也尝试过:

dispatch_async(dispatch_get_main_queue(), { () -> Void in
    self.tableView.reloadData()
})
Run Code Online (Sandbox Code Playgroud)

因为我在其他帖子中看到了这个,但它也不起作用.

谢谢你的帮助

编辑:我的整个视图控制器

class HighwaysViewController: UITableViewController {

    var highways: [Highway]!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
        // self.navigationItem.rightBarButtonItem = …
Run Code Online (Sandbox Code Playgroud)

uitableview reloaddata ios swift

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

NSAttributedString:将图像适合容器

我有一个NSAttributedString,它由HTML构成,它显示一些图像.问题是图像比容器大,我想知道如何使它们适合它.

谢谢你的帮助

html image nsattributedstring ios swift

7
推荐指数
2
解决办法
3387
查看次数

Swift:NSAttributedString 和表情符号

我使用UITextView启用了文本属性编辑的 ,当文本中有表情符号时,我在获取属性时遇到问题。

这是我使用的代码:

var textAttributes = [(attributes: [NSAttributedString.Key: Any], range: NSRange)]()
let range = NSRange(location: 0, length: textView.attributedText.length)
textView.attributedText.enumerateAttributes(in: range) { dict, range, _ in
    textAttributes.append((attributes: dict, range: range))
}

for attribute in textAttributes {
    if let swiftRange = Range(attribute.range, in: textView.text) {
        print("NSRange \(attribute.range): \(textView.text![swiftRange])")
    } else {
        print("NSRange \(attribute.range): cannot convert to Swift range")
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试使用“示例文本 ??”之类的文本时,输出如下:

NSRange {0, 12}:示例文本

NSRange {12, 1}:无法转换为 Swift 范围

NSRange {13, 1}:无法转换为 Swift 范围

如您所见,我无法获取带有表情符号的文本。

文本属性由我NSTextStorage在文本视图上应用的自定义设置。这是setAttributes …

nsattributedstring ios emoji nsrange swift

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