Tag: swift3

使用Alamofire将JSON数据的嵌套数组显示到tableview

我已经在tableview中显示了第一个json数据,但是当试图显示内部数组数据的数组数据时,它显示在表视图上的空白数据,我已经厌倦了很多方式有时它显示我索引超出范围不知道我在哪里出错或忘记编写代码,我可以在表视图中显示费用类数据,但不能显示描述数据,或者我是否需要更改我的Uidevise 这里我有模特class class Fees { var Billno = String() var DateOfReciept = String() var amount = String() var status = String() var recivedDate = String() var AmountPaid = String() var descriptions = [Description]() init(feesJson:JSON) { self.Billno = feesJson["RecieptNo"].stringValue self.DateOfReciept = feesJson["DateOfReciept"].stringValue self.amount = feesJson["dueAmount"].stringValue self.status = feesJson["Status"].stringValue self.recivedDate = feesJson["recivedDate"].stringValue self.AmountPaid = feesJson["AmountPaid"].stringValue if let […]

在不缩小内容的情况下调整精灵的大小

我用UIBezierPath创build了一个大圆圈,并使用它将其转换为Sprite, let path = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0), radius: CGFloat(226), startAngle: 0.0, endAngle: CGFloat(M_PI * 2), clockwise: false) // create a shape from the path and customize it let shape = SKShapeNode(path: path.cgPath) shape.lineWidth = 20 shape.position = center shape.strokeColor = UIColor(red:0.98, green:0.99, blue:0.99, alpha:1.00) let trackViewTexture = self.view!.texture(from: shape, crop: outerPath.bounds) let trackViewSprite […]

如何在Swift中以编程方式更改UIWebView方向

我以编程方式创build了UIWebView。 现在我想以编程方式设置它的方向(横向或纵向)。 请谁能告诉我,我怎么能做到这一点? 谢谢 import UIKit class ViewController: UIViewController, UIWebViewDelegate { override func viewDidLoad() { super.viewDidLoad() let webV:UIWebView = UIWebView(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.width, UIScreen.mainScreen().bounds.height)) webV.loadRequest(NSURLRequest(URL: NSURL(string: "http://tune.tv/humtv-live-embed")!)) webV.delegate = self; self.view.addSubview(webV) } }

拖动UIButton,而不移动到中心

所以我find了如何使用UIPanGestureRecognizer使button可拖动。 但我知道如何做的唯一方法是通过存储和拖动button的中心。 这个问题是,如果你尝试从一个angular落拖动button,button会立即从angular落移动到中心。 我正在寻找的是一个解决scheme,将保持我的手指在选定的地方,而没有立即locking中心移动。 我目前使用的代码是: func buttonDrag(pan: UIPanGestureRecognizer) { print("Being Dragged") if pan.state == .began { print("panIF") buttonCenter = button.center // store old button center }else { print("panELSE") let location = pan.location(in: view) // get pan location button.center = location // set button to where finger is } } 提前致谢。

NSMutableAttributedString不能在特定范围的tableviewcell中工作

我已经跟着这个问题,但没有解决我的问题。 我在ViewController中有一个tableview , tableviewcell有一个标签。 我想用NSStrikethroughStyleAttributeName来设置。 如果我设置完整的string作为删除线它的作品, 但如果我设置为部分它不起作用。 下面的代码为成功的结果 let strOriginalPrice = "my price" let strdiscountedPrice = "discounted price" let strPrice = strOriginalPrice+" "+strdiscountedPrice let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 2, range: NSMakeRange(0, attributeString.length)) cell.lblPrice.attributedText = attributeString 下面的代码不工作 let attributedDiscunt: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributedDiscunt.addAttribute(NSStrikethroughStyleAttributeName, value:2, range: NSMakeRange(0, strOriginalPrice.characters.count-1)) cell.lblPrice.attributedText = attributedDiscunt

numberOfSectionsInTableView不起作用

import UIKit class exploreViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var exploreTableView: UITableView! var CELLHEIGHT = 200 var SECTIONHEADER = "SECTIONHEADER" override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. exploreTableView.delegate = self exploreTableView.dataSource = self exploreTableView.register(UINib(nibName: "answerCell", bundle: nil), forCellReuseIdentifier: "cell1") } func numberOfSectionsInTableView(tableView: […]

UITableViewDelegate方法不会在Swift 3.0和Xcode 8迁移之后调用

在将我的代码库从Swift 2.2迁移到Swift 3.0之后,我注意到我的UITableView页脚没有显示出来。 事实certificate,我的UITableViewDelegate方法没有调用(例如: func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? )。 有趣的是, UITableViewDataSource方法正在被调用, 表被填充 。 我已经设置父视图控制器是表的delegate和dataSource 。 为了说明这个问题,我创build了一个示例Swift 3.0项目 ,以尽可能匹配我现有的代码库。 也许Swift 3 / Xcode 8中的一些东西我没有意识到,或者我可能会错过一些非常明显的东西。 感谢您的帮助!

如何添加两个或更多的buttonannotationView:MKAnnotationView?

我想有一个MKAnnotationView到我的地图上的引脚(使用MapKit)与下一个属性: 1)图像 2)详细button 3)另一个细节button 4)另一个细节button? 我已经做了实际添加图像和细节button与下一个代码: annotationView.detailCalloutAccessoryView = snapshotView // snapshot view is a custom view // with image and its constraints let detailsButton = UIButton(type: .detailDisclosure) annotationView.rightCalloutAccessoryView = detailsButton 所以,问题是如何添加多个button到MKAnnotationView ? 因为我见过的所有教程只是“如何添加细节button”。

如何在创build新logging时使用CloudKit在没有延迟的情况下更新TableView中的数据

在我的应用程序中有2个视图控制器。 第一个“MainViewController”显示了从私有CloudKit数据库中获取的CKRecords字段的tableView。 在VC的viewWillAppear方法中,我从CloudKit获取logging并重新加载tableview的数据,以显示用户以前保存在CloudKit中的最新获取结果。 第二个视图控制器“CreateRecordViewController”用于创buildCKRecords并将其保存到CloudKit的专用数据库。 所以我在CreateRecordViewController中创buildlogging并在MainViewController中显示它们。 问题是:当我在CreateRecordViewController创buildlogging时,它保存在CloudKit服务器上,但closures此CreateRecordViewController并转到MainViewController后,tableview并不总是及时更新。 这是我CreateRecordViewController中保存logging的代码: CloudKitManager.sharedInstance.privateDatabase.save(myRecord) { (savedRecord, error) -> Void in if error == nil { print("successfully saved record code: \(savedRecord)") } else { // Insert error handling print("error Saving Data to iCloud: \(error.debugDescription)") } } logging保存后,我closuresCreateRecordViewController并查看MainViewController。 正如我之前在viewWillAppear of MainViewController中所说的,我检查iCloud是否可用,如果可用,我使用CloudKit中的查询获取所有logging,并在tableView中显示它们。 override func viewWillAppear(_ animated: Bool) { CKContainer.default().accountStatus { (accountStatus, error) in switch […]

如何获取当月的开始date和结束date(Swift 3)

我试图以dd/MM/yyyy格式获取当前月份的开始date和结束date。 我尝试使用扩展在这个问题的答案。但它似乎不是我想要的(格式是不同的,它也给了我上个月的最后一个date和当前月最后一个date)。 有人能帮我吗。 扩展类: extension Date { func startOfMonth() -> Date? { let comp: DateComponents = Calendar.current.dateComponents([.year, .month, .hour], from: Calendar.current.startOfDay(for: self)) return Calendar.current.date(from: comp)! } func endOfMonth() -> Date? { var comp: DateComponents = Calendar.current.dateComponents([.month, .day, .hour], from: Calendar.current.startOfDay(for: self)) comp.month = 1 comp.day = -1 return Calendar.current.date(byAdding: comp, to: self.startOfMonth()!) } } 我的结构: […]