Tag: swift

Swift – 以编程方式将自定义Xib视图添加为子视图

我做了一个定制的xib,我已经在我的故事板中使用过,我只想创build一个自定义视图resize的实例,然后将其作为子视图添加到uiscrollview。 我试过在我的视图控制器的viewdidload func中使用这块代码 let cardView = CardView(coder: NSCoder()) cardView!.frame.size.width = 100 cardView!.frame.size.height = 100 scrollView.addSubview(cardView!) 但我得到这个错误 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -containsValueForKey: cannot be sent to an abstract object of class NSCoder: Create a concrete instance!' 编辑:这是连接到CardView.xib的swift文件的代码 import UIKit class CardView: UIView { @IBOutlet var view: UIView! @IBOutlet weak var cornerView: […]

绑定Json和post请求

经过了一整天,并检查堆栈溢出和几个论坛上的许多链接,我无法破解它:我认为许多swift开发人员发现它很容易,但我无法破解它,请帮助 我有一个url和一个JSON来绑定和获取JSON响应 urlPOST: http://myurl/myurl.com…….// JSON请求: { "BookingId": "1501433021", "ProductType": "0", "Client": "1", "OriginAirport": { "CityCode": "NYC", "CityName": "New York", "AirportCode": "NYC", "AirportName": "New York City All Airports", "Country": "US", "Terminal": "" }, "DestinationAirport": { "CityCode": "LON", "CityName": "London", "AirportCode": "LON", "AirportName": "London All Airports", "Country": "GB", "Terminal": "" }, "TravelDate": "2016-10-19T05:07:57.865-0400 ", "ReturnDate": "2016-10-21T05:08:02.832-0400 ", […]

如何将videopath转换为NSData

我用DKImagePicker从图库中获取多个video。 能够获取video,但不能转换为NSData 。 也从服务器接收错误。 Error Domain=NSCocoaErrorDomain Code=257 "The file “IMG_0040.MOV” couldn't be opened because you don't have permission to view it." UserInfo={NSFilePath=/var/mobile/Media/DCIM/100APPLE/IMG_0040.MOV, NSUnderlyingError=0x172e5f6b0 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}} 可能不会正确转换为NSData或可能是其他问题。 我到目前为止尝试的是: let videoURL = User.sharedInstance.arrRoomGalleryVideos.objectAtIndex(index) as? NSURL var movieData: NSData? do { let video = try NSData(contentsOfURL: videoURL!, options: .DataReadingMappedIfSafe) print("video", video) multipartFormData.appendBodyPart(data: video, name: […]

无法设置URLRequest授权标头

由于swift 3更新,我将我的请求从NSMutableURLRequest更改为URLRequest。 之后,所有我的请求停止工作,由于凭证无效问题。 已经尝试过,search一切。 我的服务继续和以前一样,并从请求模拟器testing我的请求,并没有问题。 let url : NSString = "http://url.service.com/method?param=\(name)" as NSString var request = URLRequest(url: URL(string: url.addingPercentEscapes(using: String.Encoding.utf8.rawValue)!)!) request.httpMethod = "POST" request.setAuthorizationHeader() URLSession.shared.dataTask(with: request) {data, response, err in do { //something } catch let error1 as NSError { //something } }.resume() 我的setAuthorizationHeader()扩展 extension URLRequest { mutating func setAuthorizationHeader(){ let data = "user:password".data(using: String.Encoding.utf8) […]

(lldb)与Firebase的错误

每当我点击一个特定的标签,我得到一个lldb错误。 该选项卡被称为帐户,它应该从一个名为“请求”的子节点拉数据,并显示在列表(表视图控制器)的数据。 我以前多次做过这个。 我甚至使用自己的回收代码来完成这个任务,但是错误一直在显示。 我已经确保每个button/标签都连接到视图控制器,并确保没有断开连接。 错误消息是说我的请求对象不符合密钥代码,但事实并非如此。 还有什么呢? 这是代码和一些截图: 这是我正在使用的方法。 只有当我调用这个函数时才会出现这个错误。 除此之外,屏幕只是空白,所以我认为这个问题必须在function内。 顺便说一句,requestsArray是一个声明为这样的请求数组: var requestsArray = [requests]() 下面是来自该视图控制器的其余代码: 编辑

数组中string的UISearchBar

我正在尝试创build一个带有节标题,标题文本和字幕文本的字典types的应用程序。 我设法让一切工作使用下面的代码。 唯一我无法弄清楚的是如何过滤UISearchBar来显示数组中的string[Coptic]的结果。 这甚至可能是我组织一切的方式,还是我需要重组? 有没有人有什么build议? 我遗漏了底部的updateSearchResults空白代码,因为我不知道该编码什么。 class Gamma: UITableViewController, UISearchBarDelegate, UISearchResultsUpdating { struct words { var sectionName : String! var coptic : [String]! var english : [String]! } var array = [words]() var filtered = [words]() var filtered2 = UITableViewController() var indexarray = ["Ga", "Ge", "Gy", "Gn", "Go", "Gr", "Gw"] let searchController = UISearchController(searchResultsController: nil) […]

从UITableViewCell调用UIButton动作

我dynamic地在我的UITableviewCell类中创build了几个button,如下所示: for (clientObjectId, _) in connectedObjectIds { self.clientNameButton = UIButton(type: UIButtonType.System) as UIButton self.clientNameButton.titleLabel?.lineBreakMode = NSLineBreakMode.ByTruncatingTail self.clientNameButton.frame = CGRectMake(self.leftSideSpaceForUsersAndUserLabel, clientNameButtonFrameHeight, self.nameButtonWidth, self.nameButtonHeight) self.clientNameButton.setTitle(self.userObjectIdsAndNames[clientObjectId], forState: UIControlState.Normal) self.clientNameButton.titleLabel!.font = UIFont(name: "Helvetica", size: 12.0) self.clientNameButton.addTarget(self, action: "asdf:", forControlEvents: UIControlEvents.TouchUpInside) self.nameButtons.append(self.clientNameButton) self.addSubview(self.clientNameButton) } 但是,我似乎无法find一种方法来调用我的表视图单元格类中的以下function: func asdf(sender:UIButton) { print("Button tapped") } 我不太在乎能够在我的UITableViewCell类中调用它,就像在我的表视图类中调用函数一样。 有人有解决这个问题?

无法将数据从CoreData加载到tableview中

我正在学习如何使用CoreData。 我有一个添加button,这只是一个文本字段和保存button视图的tableView。 按下button时,文本字段中的string保存在CoreData数据库中: @IBOutlet weak var name: UITextField! @IBAction func onSave(sender: UIBarButtonItem) { saveItem(name.text!) self.dismissViewControllerAnimated(true, completion: nil) } private func saveItem(itemName: String) { let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let managedContext = appDelegate.managedObjectContext let entity = NSEntityDescription.entityForName("Item", inManagedObjectContext: managedContext) let item = NSManagedObject(entity: entity!, insertIntoManagedObjectContext: managedContext) item.setPrimitiveValue(itemName, forKey: "name") do { try managedContext.save() listItems.append(item) }catch […]

Xcode7:如何邮件崩溃报告在迅速

我的小任务是,如何邮寄崩溃报告? 我不知道这个例子是对还是错。 编码: override func viewDidLoad() { super.viewDidLoad() func exceptionHandler(exception : NSException) { print("\n\n \(exception)") print("\n\n \(exception.callStackSymbols)") mailAcn() // SENDING MAIL ACTION WHEN EXCEPTION CAUGHT } NSSetUncaughtExceptionHandler(exceptionHandler) //Error: AC Function pointer cannot be formed from a local function captures context // Do any additional setup after loading the view, typically from a nib. } 我正在关注这个链接, […]

UIFocusGuide UITableView和UIButton

我很难创build一个将从UITableView跳转到UIButton的UIFocusGuide。 这里是debugging器上下文截图: 这是执行: override func viewDidLoad() { super.viewDidLoad() self.tableView.delegate = self self.tableView.dataSource = self // add the focus guide self.view.addLayoutGuide(focusGuide) // add the anchors self.focusGuide.leftAnchor.constraintEqualToAnchor(self.button.leftAnchor).active = true self.focusGuide.topAnchor.constraintEqualToAnchor(self.tableView.topAnchor).active = true self.focusGuide.widthAnchor.constraintEqualToAnchor(self.button.widthAnchor).active = true self.focusGuide.heightAnchor.constraintEqualToAnchor(self.tableView.heightAnchor).active = true } override func didUpdateFocusInContext(context: UIFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) { guard let nextFocusedView = context.nextFocusedView else { return } switch […]