【发布时间】:2018-08-03 16:40:12
【问题描述】:
我在以前在所有其他测试版上工作的文件上收到此错误,由于某种原因,在 beta 4 xcode 中它显示此错误,它是整个项目中唯一执行此操作的文件,我不确定为什么它只为 beta 4 做这件事,有什么想法吗?我试过使用默认的初始化,但我得到一个编译错误。
我认为要放入的代码太多,所以直接将文件改为。
https://www.dropbox.com/s/7a6q1oyj2qnshu0/SearchView.swift
import UIKit
import CloudKit
import Foundation
import QuartzCore
import MediaPlayer
import AVFoundation
import CoreMedia
class SearchViewController: UIViewController, UITableViewDelegate,UITableViewDataSource, UISearchBarDelegate, UIScrollViewDelegate, SearchAPIProtocol {
enum UIUserInterfaceIdiom : Int {
case Unspecified
case Phone // iPhone and iPod touch style UI
case Pad // iPad style UI
}
var searchCell: SearchViewCell = SearchViewCell()
var progressView: CGCircleProgressView = CGCircleProgressView()
var tableData = NSArray()
var buttonIndex: NSIndexPath?
var previousIndex: NSIndexPath?
var songPlayer = AVPlayer()
var hidden = Bool()
var startContentOffset = CGFloat()
var lastContentOffset = CGFloat()
var firstAmount = Int()
var imageCache = NSMutableDictionary()
var searchOpen: Bool?
var searchAPI: SearchAPIController = SearchAPIController()
@IBOutlet var tableView: UITableView!
@IBOutlet var searchBar: UISearchBar!
@IBOutlet var sBar: UIView!
override func viewDidLoad() {
super.viewDidLoad()
var nib = UINib(nibName: "SearchViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "Cell")
searchAPI.delegate = self
searchAPI.searchItunesFor("Justin")
// container = CKContainer.defaultContainer()
//publicDatabase = container?.privateCloudDatabase
self.setUpSearchBar()
hidden = false
self.tableView.contentInset = UIEdgeInsetsMake(108, 0, 0, 0)
var subViews: UIView = searchBar.subviews.bridgeToObjectiveC().lastObject as UIView
var textView: UITextField = subViews.subviews.bridgeToObjectiveC().objectAtIndex(1) as UITextField
textView.textColor = UIColor.whiteColor()
// Do any additional setup after loading the view, typically from a nib.
}
func setUpSearchBar() {
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Dark)) as UIVisualEffectView
visualEffectView.frame = sBar.bounds
sBar.addSubview(visualEffectView)
sBar.sendSubviewToBack(visualEffectView)
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.CenterX,
relatedBy:.Equal, toItem:sBar,
attribute:.CenterX, multiplier:1, constant:0))
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.CenterY,
relatedBy:.Equal, toItem:sBar,
attribute:.CenterY, multiplier:1, constant:0))
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Width,
relatedBy:.Equal, toItem:sBar,
attribute:.Width, multiplier:1, constant:0))
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Height,
relatedBy:.Equal, toItem:sBar,
attribute:.Height, multiplier:1, constant:0))
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Leading,
relatedBy:.Equal, toItem:sBar,
attribute:.Leading, multiplier:1, constant:0))
sBar.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Trailing,
relatedBy:.Equal, toItem:sBar,
attribute:.Trailing, multiplier:1, constant:0))
visualEffectView.setTranslatesAutoresizingMaskIntoConstraints(false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
并显示表格视图:
func tableView(tableView: UITableView!, heightForHeaderInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView!, viewForFooterInSection section: Int) -> UIView {
var view = UIView(frame: CGRect.zeroRect)
return view
}
func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
return 81
}
func tableView(tableView: UITableView!, heightForFootInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
if self.tableData.count > firstAmount {
return firstAmount + 1
} else {
return 0
}
//return self.tableData!.count
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let CellIndentifier: NSString = "Cell"
let moreID: String = "moreCell"
var searchCell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as SearchViewCell
var rowData: NSDictionary = self.tableData[indexPath!.row] as NSDictionary
var rows = indexPath.row
if rows == firstAmount {
searchCell.loadMoreView.hidden = false
} else {
searchCell.selectionStyle = UITableViewCellSelectionStyle.None
searchCell.clipsToBounds = true
searchCell.loadMoreView.hidden = true
var artistName = rowData["artistName"] as String
var trackName = rowData["trackName"] as String
var previewURL = rowData["previewUrl"] as String
//var artistURL = rowData["artistViewUrl"] as String
//var buyURL = rowData["trackViewUrl"] as String
var artworkURL = rowData["artworkUrl100"] as String
searchCell.previewButton.addTarget(self, action: "flipButton:", forControlEvents: UIControlEvents.TouchUpInside)
searchCell.songName.text = trackName
searchCell.artistName.text = artistName
var layer: CALayer = searchCell.blurView.layer
layer.shadowOffset = CGSizeMake(0, 0)
layer.shadowColor = UIColor(white: 0.0, alpha: 1.0).CGColor
layer.shadowRadius = 1.0
layer.shadowOpacity = 0.5
searchCell.backImage.clipsToBounds = true
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Dark)) as UIVisualEffectView
visualEffectView.frame = searchCell.blurView.bounds
searchCell.blurView.addSubview(visualEffectView)
searchCell.blurView.sendSubviewToBack(visualEffectView)
// NSLayoutConstraint.deactivateConstraints(searchCell.blurView.constraints())
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.CenterX,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.CenterX, multiplier:1, constant:0))
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.CenterY,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.CenterY, multiplier:1, constant:0))
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Width,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.Width, multiplier:1, constant:0))
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Height,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.Height, multiplier:1, constant:0))
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Leading,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.Leading, multiplier:1, constant:0))
searchCell.blurView.addConstraint(NSLayoutConstraint(
item:visualEffectView, attribute:.Trailing,
relatedBy:.Equal, toItem:searchCell.blurView,
attribute:.Trailing, multiplier:1, constant:0))
visualEffectView.setTranslatesAutoresizingMaskIntoConstraints(false)
var placeHolder = UIImage(named: "placeHolder.png")
searchCell.artworkIMG.image = placeHolder
searchCell.backImage.image = placeHolder
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
var urlString: NSString = rowData["artworkUrl100"] as NSString
var image: UIImage? = self.imageCache.valueForKey(urlString) as? UIImage
if( !image? ) {
var imgURL: NSURL = NSURL(string: urlString)
var request: NSURLRequest = NSURLRequest(URL: imgURL)
var urlConnection: NSURLConnection = NSURLConnection(request: request, delegate: self)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
if !error? {
image = UIImage(data: data)
self.imageCache.setValue(image, forKey: urlString)
searchCell.artworkIMG.image = image
searchCell.backImage.image = image
} else {
println("Error: \(error.localizedDescription)")
}
})
} else {
searchCell.artworkIMG.image = image
searchCell.backImage.image = image
}
})
}
return searchCell
}
func tableView(tableView: UITableView!, willDisplayCell cell: UITableViewCell!, forRowAtIndexPath indexPath: NSIndexPath!) {
cell.layer.transform = CATransform3DMakeScale(0.1,0.1,1)
/*UIView.animateWithDuration(0.25, animations: {
cell.layer.transform = CATransform3DMakeScale(1,1,1)
})*/
UIView.animateWithDuration(0.4, animations: {
cell.layer.transform = CATransform3DMakeScale(1.1,1.1,1.1)
}, completion: {(value: Bool) in
cell.layer.transform = CATransform3DMakeScale(1,1,1)
})
}
【问题讨论】:
-
代码很多?链接到文件会更好吗?
-
您可以显示相关部分而不显示全部。例如,显示您的类以及至少其初始化程序的第一行...
-
代码已添加@jtbandes