我正在尝试将searchBar添加到navigationBar.我研究了一下,这是我到目前为止所做的:
使用此代码的navigationBar似乎没有任何问题.
searchBar = UISearchBar(frame: CGRectMake(0, 0, 320, 44))
searchBar?.delegate = self
searchBar?.showsCancelButton = true
searchController = UISearchDisplayController()
searchController?.delegate = self
searchController?.searchResultsDelegate = self
searchController?.displaysSearchBarInNavigationBar = true
Run Code Online (Sandbox Code Playgroud) 我在我的Cell Subclass中有UILabel,假设有一个标题.标题的大小可以是各种长度,因此我需要调整UILabel的大小以适应文本,并防止文本不长,我还需要能够设置maxHeight.宽度应该相同.如何在tableViewCell子类中的swift中创建这样的代码?
到目前为止,我在awakeFromNib中有这个
theTitleLabel?.font = UIFont(name: "HelveticaNeue", size: 13)
theTitleLabel?.textColor = UIColor(rgba: "#4F4E4F")
theTitleLabel?.numberOfLines = 0
theTitleLabel?.lineBreakMode = NSLineBreakMode.ByTruncatingTail
Run Code Online (Sandbox Code Playgroud) 我用标准的html验证创建了以下表单.对于这种形式,我想在按下提交按钮时避免刷新页面.因此我在我的jquery代码中添加了preventDefault().通过不刷新页面工作,但它也删除了html5验证?我怎么能同时申请这两件事?
形成
<form method="post" action="">
<div class="reg_section personal_info">
<input type="text" name="username" id="title" value="" placeholder="title" required="required" maxlength="25">
<textarea name="textarea" id="description" value="" placeholder="Beskrivelse" required="required" minlength="100"></textarea>
</div>
<div>
<span class="submit" style="text-align: left; padding: 0 10px;"><input type="submit" id="insert" value="Tilføj"></span>
<span class="submit" style="text-align: right; padding: 0 10px;"><input TYPE="button" value="Fortryd" onclick="div_hide();"></span>
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
jQuery的
$("#insert").click(function(e) {
e.preventDefault(); // prevent default form submit
if(!$('#description').val() == "" && !$('#title').val() == "" && $('#description').val().length >= 100) {
div_hide();
$.post("insert.php",
{
title: $('#title').val(),
body: $('#description').val(),
longitude: currentMarker.lng(),
latitude: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 knex 创建一个查询,使用 postgres 作为数据库。但是,当我运行代码时,它不断询问
错误:找不到模块“sqlite3”
即使我已经添加pg到我的 knexfile.
询问
var data = {
id: leagueId,
slug: leagueSlug,
createdAt: new Date()
};
var query = knex('league').insert(data).toString();
query += ' on duplicate key update ' + knex.raw('createdAt= ?, id = ?',[new Date(), id]);
knex.raw(query);
Run Code Online (Sandbox Code Playgroud)
knex文件
module.exports = {
development: {
client: 'pg',
connection: {
user: 'test',
database: 'test'
}
},
production: {
client: 'pg',
connection: process.env.DATABASE_URL
}
};
Run Code Online (Sandbox Code Playgroud)
索引.js
var express = require('express');
var request = require('request');
var parse = …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个表单,其中两个字段都是可选的,但是在设置null和blank. 我究竟做错了什么?
错误
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'blank'
Run Code Online (Sandbox Code Playgroud)
表格.py
class EditProfile(forms.Form):
"""
A form that lets a user change their profile information
"""
first_name = forms.CharField(
label=("Fornavn"),
strip=False,
blank=True,
null=True
)
last_name = forms.CharField(
label=("Efternavn"),
strip=False,
blank=True,
null=True,
)
def __init__(self, user, *args, **kwargs):
self.user = user
super().__init__(*args, **kwargs)
def save(self, commit=True):
first_name = self.cleaned_data["first_name"]
last_name = self.cleaned_data["last_name"]
self.user.first_name = first_name
self.user.last_name = last_name
if commit:
self.user.save()
return self.user
Run Code Online (Sandbox Code Playgroud) 我有一个现有的项目,我想从中添加名为CoreActionSheetPicker的框架
https://github.com/skywinder/ActionSheetPicker-3.0
Run Code Online (Sandbox Code Playgroud)
问题是我似乎无法将框架添加到我的项目中?当我将框架拉到我现有的项目时,没有添加下面的文件,当我尝试导入它时说它不存在
import CoreActionSheetPicker
Run Code Online (Sandbox Code Playgroud)
我想在没有cocoaPods的情况下这样做.这样做的步骤是什么?我正在使用swift.我首先需要创建一个WorkSpace吗?
我正在尝试下载 csv 文件,但它似乎适用于除 safari 之外的所有浏览器?怎么会这样。在 safari 中它只是在浏览器中显示?
这是我的代码:
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var blob = new Blob([data], {type: "text/csv;charset=utf-8"}),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
setTimeout(function(){
window.URL.revokeObjectURL(url);
}, 100);
};
}());
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置默认的selectedCell,默认情况下,我的意思是该单元格具有特定的selectedCellBackgroundView.然而即使我已经为它创建了一个方法,它似乎不起作用.它selectedBackgroundView在第一个细胞上没有显示任何内容?我手动选择单元格时工作正常.我究竟做错了什么?
viewDidLoad和viewWillAppear都试过了
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
let cell = tableView!.cellForRowAtIndexPath(indexPath)! as UITableViewCell
applySelectionChangesToCell(cell)
Run Code Online (Sandbox Code Playgroud)
didSelectRowAtIndexPath方法
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
applySelectionChangesToCell(cell)
NSUserDefaults.standardUserDefaults().setInteger(menuArray[indexPath.row].id!, forKey: "leagueId")
self.sideMenuViewController.hideMenuViewController()
}
Run Code Online (Sandbox Code Playgroud)
applySelectionChangesToCell
func applySelectionChangesToCell(cell:UITableViewCell) {
let backgroundSelectionView = UIView(frame: cell.bounds)
backgroundSelectionView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.1)
cell.selectedBackgroundView = backgroundSelectionView
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试将tableViewCell高度设置为等于attributedString单元格内部的高度.但无论我做什么,似乎都没有正确的尺寸.这是我到目前为止所尝试的
cellHeight
//Convert description to NSAttributedString and get height
//width is equal to screen width - right and left offset
//at the end add the bottom and height offset to the cell height
return detailPetViewModel!.description
.lineSpacing(spacing: 4)
.heightWithConstrainedWidth(width: Sizes.screenWidth - 40) + 10
Run Code Online (Sandbox Code Playgroud)
在单元子类中自定义descLabel
//Customize descLabel
descLabel.font = FontFamily.Avenir.Regular.font(size: 16)
descLabel.textColor = UIColor(named: .SecondaryTextColor)
//Multiple lines
descLabel.numberOfLines = 0
descLabel.lineBreakMode = .byWordWrapping
descLabel.sizeToFit()
Run Code Online (Sandbox Code Playgroud)
linespacing扩展名
extension String {
func lineSpacing(spacing: CGFloat) -> NSAttributedString {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing …Run Code Online (Sandbox Code Playgroud) 我正在尝试按距当前位置的距离对数组进行排序。首先,您会看到organizationObject其中包含不同值的,然后我们得到的位置是一组不同位置的数组。之所以如此,array是因为一个组织可以有多个位置。然后在ViewController中,我创建了一组测试对象并将其追加到数组中。我的问题是如何orgArray根据distanceFromLocation 对此进行排序?如果位置数组中有多个位置,则应采用最接近的位置。
OrganizationObject
class OrganizationObject {
var id: Int
var name: String
var image: UIImage
var locations: [CLLocationCoordinate2D]
init(id: Int, name: String, image: UIImage, locations: [CLLocationCoordinate2D]) {
self.id = id
self.name = name
self.image = image
self.locations = locations
}
}
Run Code Online (Sandbox Code Playgroud)
将测试对象追加到数组。在viewDidLoad中
orgArray.append(OrganizationObject(id: 0, name: "Statens Museum For Kunst", image: UIImage(named: "statensmuseum.jpg")!, locations: [CLLocationCoordinate2D(latitude: 55.6888127, longitude: 12.578330300000061)]))
orgArray.append(OrganizationObject(id: 0, name: "7 eleven", image: UIImage(named: "7eleven.jpg")!, locations: [CLLocationCoordinate2D(latitude: 58.334682, longitude: 8.231820900000002)]))
orgArray.append(OrganizationObject(id: 0, name: "Kongens …Run Code Online (Sandbox Code Playgroud) ios ×6
swift ×6
iphone ×3
javascript ×2
arrays ×1
django ×1
frameworks ×1
html ×1
html5 ×1
jquery ×1
knex.js ×1
node.js ×1
postgresql ×1
python ×1
safari ×1
sorting ×1
sqlite ×1
uilabel ×1
uisearchbar ×1
uitableview ×1
validation ×1