我试图设置searchBar为tableHeaderView内部viewDidLoad:
override func viewDidLoad() {
super.viewDidLoad()
// SearchController initializiation
self.searchController = UISearchController.init(searchResultsController: nil)
self.searchController.delegate = self
self.searchController.searchBar.delegate = self
self.searchController.searchBar.sizeToFit()
self.searchController.searchResultsUpdater = self
self.searchController.searchBar.barTintColor = UIColor.white
self.searchController.searchBar.keyboardAppearance = .default
self.searchController.searchBar.backgroundColor = UIColor.white
self.searchController.hidesNavigationBarDuringPresentation = true
self.searchController.obscuresBackgroundDuringPresentation = false
self.tableView.tableHeaderView = self.searchController.searchBar
self.definesPresentationContext = true
self.fetch()
self.tableView.reloadData()
}
Run Code Online (Sandbox Code Playgroud)
这是我的fetch()功能:
func fetch() {
let fetchRequest:NSFetchRequest<Phone> = Phone.fetchRequest()
fetchRequest.sortDescriptors = [NSSortDescriptor.init(key: "header", ascending: true), NSSortDescriptor.init(key: "date", ascending: true)]
self.fetchedResultsController = NSFetchedResultsController.init(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: …Run Code Online (Sandbox Code Playgroud) 我有一个延伸的Swift类UITableViewController.它有这个功能
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {...}
Run Code Online (Sandbox Code Playgroud)
有必要,我需要在一个地方以编程方式调用此函数
self.tableView(tableView, cellForRowAt: 1)
Run Code Online (Sandbox Code Playgroud)
如何以编程方式调用此函数?
我正在使用自动调整项目中的单元格大小.我希望将单元格保持在最小值height,但是我无法在内容视图中为我的单元格设置最小height 约束(因为它在" 添加新约束"视图中显示为灰色:
无论如何都要为我的细胞添加最小height 约束?
游戏应用程序使用了高达1GB的RAM
我正在使用swift 2.2,我在单元格内部有一个集合视图,我有一个标签.我想在按钮点击的UICollection视图中更改标签文本值,而不使用重新加载整个uiCollection视图.我无法在我的场景中使用collectionView.reloadData().我希望不使用它就可以.只是为了更新collectionview中特定项目中的一个标签.任何帮助?
我打算使用,UIAlertController但是当我想展示它时,我看到了这个错误:
使用未解析的标识符“存在”
这是我的代码:
func showAllert(title: String, msg: String, vc: UIViewController){
let alert = UIAlertController(title: title, message: msg, preferredStyle: .alert)
let action = UIAlertAction(title: "ok", style: .default, handler: nil)
alert.addAction(action)
present(alert, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) 我试图用闭包来实现自定义函数。但它不受#selector.
下面是一个例子:
class Core: NSObject {
static let shared:Core = Core.init()
func button(viewController: UIViewController, button: UIButton, title: String, color: UIColor, completion: () -> Void) {
button.layer.cornerRadius = button.bounds.width / 2
button.setTitle(title, for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.backgroundColor = color
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 18)
button.addTarget(viewController, action: #selector(completion()), for: .touchUpInside)
}
}
Run Code Online (Sandbox Code Playgroud)
Xcode 给了我一个构建时间问题:
“#selector”的参数不引用“@objc”方法、属性或初始值设定项
我有我的模特课
class CPOption : Object, Mappable
{
dynamic var optionId : Int64 = 0
override static func primaryKey() -> String? {
return "optionId"
}
required convenience init?(map: Map) {
self.init()
}
func mapping(map: Map) {
optionId <- map["id"] //**Here i need to transform string to Int64**
}
}
Run Code Online (Sandbox Code Playgroud)
我的输入JSON包含optionId作为String.
"options": [
{
"id": "5121",
},
]
Run Code Online (Sandbox Code Playgroud)
我需要在Objectmapper Map函数中将此传入的字符串类型转换为Int64.
默认情况下,启动屏幕提供状态栏。是否可以在启动屏幕中隐藏状态栏,例如Twitter应用程序(iOS)。
private func setTitle(title:String, subtitle:String, animate: Bool) -> UIView {
let titleLabel = UILabel(frame: CGRect(x:0, y:-5, width:0, height:0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.gray
titleLabel.font = UIFont.boldSystemFont(ofSize: 15)
titleLabel.text = title
titleLabel.adjustsFontSizeToFitWidth = true
let subtitleLabel = UILabel(frame: CGRect(x:0, y:18, width:0, height:0))
subtitleLabel.backgroundColor = UIColor.clear
subtitleLabel.textColor = UIColor.black
subtitleLabel.font = UIFont.systemFont(ofSize: 12)
subtitleLabel.text = subtitle
subtitleLabel.adjustsFontSizeToFitWidth = true
let titleView = UIView(frame: CGRect(x:0, y:0, width:max(titleLabel.frame.size.width, subtitleLabel.frame.size.width), height:30))
let titleViewTapGesture = UITapGestureRecognizer(target: self, action: #selector(titleViewTapped(sender:)))
titleView.addGestureRecognizer(titleViewTapGesture)
titleView.addSubview(titleLabel)
if animate{
subtitleLabel.alpha = 0.0 …Run Code Online (Sandbox Code Playgroud) 我试图设置UIImage的CGImage作为layer的内容,然后添加layer到view的layer。
黄色视图的中心应该是五颗星。那就是我想要的。
不过好像星星的中心与对齐origin的view。我该怎么做才能纠正它?
func putOnStars() {
let rect = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
rect.backgroundColor = .yellow
view.addSubview(rect)
let baseLayer = CALayer()
baseLayer.contents = UIImage(named: "stars")?.cgImage
baseLayer.contentsGravity = kCAGravityCenter
rect.layer.addSublayer(baseLayer)
}
Run Code Online (Sandbox Code Playgroud)
swift ×12
ios ×7
uitableview ×2
autolayout ×1
calayer ×1
cgimage ×1
closures ×1
core-data ×1
func ×1
json ×1
objective-c ×1
objectmapper ×1
realm ×1
selector ×1
swift3 ×1
uilabel ×1
uistatusbar ×1
uitabbar ×1
uitabbaritem ×1
uiview ×1
viewdidload ×1
xcode ×1