小编Tom*_*Tom的帖子

使用selectRowAtIndexPath以编程方式选择所有TableView行

我正在尝试使用以下代码以编程方式选择tableview中的所有行:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell:myTableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as! myTableViewCell

     cell.accessoryType = .None

    if allJobsSelected {

        let bgColorView = UIView()
        bgColorView.backgroundColor = UIColor(red: 250/255, green: 182/255, blue: 17/255, alpha: 1)
        cell.contentView.backgroundColor = UIColor(red: 250/255, green: 182/255, blue: 17/255, alpha: 1)
        cell.selectedBackgroundView = bgColorView
        cell.accessoryType = .Checkmark
        cell.highlighted = false

        cell.selected = true
        //  cell.accessoryType = .Checkmark
        self.tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)
        self.tableView(self.tableView, didSelectRowAtIndexPath: indexPath)

    }

    var job: Jobs!

    job = jobs[UInt(indexPath.row)] as! Jobs

    cell.reports2JobTitle.text …
Run Code Online (Sandbox Code Playgroud)

uitableview didselectrowatindexpath ios swift

6
推荐指数
2
解决办法
9293
查看次数

Swift 表单验证 - 检查是否输入了 Int 或 String

我正在尝试验证表单以确保用户输入的是整数而不是字符串。我可以检查数字是否为整数,如下所示:

 var possibleNumber = timeRetrieved.text
    convertedNumber = possibleNumber.toInt()
    // convertedNumber is inferred to be of type "Int?", or "optional Int"

    if convertedNumber != nil {

        println("It's a number!")

        totalTime = convertedNumber!


    }
Run Code Online (Sandbox Code Playgroud)

我的问题是我想确保用户没有输入任何文本、双打等。我只想要整数。以下代码不起作用,因为如果变量是整数,它的计算结果为 true。如果变量不是整数,我应该使用什么代码来评估?

if convertedNumber != nil  {


        let alertController = UIAlertController(title: "Validation Error", message: "You must enter an integer number!", preferredStyle: .Alert)
        let alertAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Destructive, handler: {(alert : UIAlertAction!) in
            alertController.dismissViewControllerAnimated(true, completion: nil)
        })
        alertController.addAction(alertAction)
        presentViewController(alertController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

string validation integer swift

2
推荐指数
1
解决办法
2万
查看次数

NSNotificationCenter使用SpriteKit导致EXC_BAD_ACCESS错误

我正在使用NSNotificationCenter试图控制SpriteKit中的计时器.我第一次进入SKScene时代码运行正常,但是当我尝试重新进入SKScene时,我收到了EXC_BAD_ACCESS错误.我认为这与removeObserver函数有关.我不确定何时删除观察者,我试图在prepareForSegue函数中执行此操作但没有成功.我的viewController如下:

class JobStartedViewController: UIViewController {



var titleOfJob: String = ""

override func viewDidLoad() {
    super.viewDidLoad()

    let skView = self.view as! SKView

  let scene:SKScene = GameScene.init(size: skView.bounds.size)

    NSNotificationCenter.defaultCenter().postNotificationName("stopTimerNotification", object: nil)
    NSNotificationCenter.defaultCenter().postNotificationName("startTimerNotification", object: nil)

    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = true

    /* Set the scale mode to scale to fit the window */
    scene.scaleMode = .AspectFill

    skView.presentScene(scene)
}
Run Code Online (Sandbox Code Playgroud)

我将观察者添加到我的GameScene.swift中,如下所示:

class GameScene: SKScene {   


override func didMoveToView(view: SKView) {


    NSNotificationCenter.defaultCenter().addObserver(self, selector: "stopTimerInBackground:", name:"stopTimerNotification", object: nil)
     NSNotificationCenter.defaultCenter().addObserver(self, …
Run Code Online (Sandbox Code Playgroud)

nsnotificationcenter ios sprite-kit swift

2
推荐指数
1
解决办法
984
查看次数

使用不同坐标系注释 PDF

我正在使用 PDFKIT 在 pdf 上画一条线。我覆盖触摸开始,移动等如下记录我在pdfView的documentView上的触摸如下:

 override func touchesMoved(_ touches: Set<UITouch>,
                           with event: UIEvent?) {
    // 6
    swiped = true
    if let touch = touches.first {
        let currentPoint = touch.location(in: pdfView.documentView)
       drawLineFrom(fromPoint: lastPoint, toPoint: currentPoint)
        addAnnotation(fromPoint: lastPoint, toPoint: currentPoint)

        // 7
        lastPoint = currentPoint

    }
}
Run Code Online (Sandbox Code Playgroud)

但是,正如您从下面的图片中看到的(黑线是我触摸屏幕的位置,红线是绘制注释的位置)。触摸坐标系是屏幕左上角的 (0,0),而 pdf 是从屏幕左下角 (0,0) 注释的。

插入的 iPad 图像

我的添加注解功能如下:

func addAnnotation(fromPoint: CGPoint, toPoint: CGPoint) {

    let page = pdfView.document?.page(at: 0)
    let bounds = CGRect(x: 0, y: 0, width: 600, height: 600)
    let line = PDFAnnotation(bounds: bounds, forType: …
Run Code Online (Sandbox Code Playgroud)

annotations touch pdfkit ios swift

0
推荐指数
1
解决办法
730
查看次数