小编Ste*_*Fox的帖子

如何在Swift(iOS 7)中向UIAlertView添加操作

我想在重试按钮中添加一个动作,但是当用户按下重试按钮时没有任何反应.

var createAccountErrorAlert: UIAlertView = UIAlertView()

createAccountErrorAlert.delegate = self                

createAccountErrorAlert.title = "Oops"
createAccountErrorAlert.message = "Could not create account!"
createAccountErrorAlert.addButtonWithTitle("Dismiss")
createAccountErrorAlert.addButtonWithTitle("Retry")

createAccountErrorAlert.show()
Run Code Online (Sandbox Code Playgroud)

确定按钮索引的功能?

func alertView(View: UIAlertView!, clickedButtonAtIndex buttonIndex: Int){

    switch buttonIndex{

    case 1:
        createAccount()

    default:
        //Some code here..

    }
}
Run Code Online (Sandbox Code Playgroud)

ios swift

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

iOS无法识别的选择器发送到Swift中的实例

当用户按下UIButton时,我遇到了问题.我一直收到错误说:无法识别的选择器发送到实例

override func viewDidLoad() {
    super.viewDidLoad()

    button.addTarget(self, action: "buttonClick", forControlEvents: UIControlEvents.TouchUpInside)
    button.setTitle("Print", forState: UIControlState.Normal)
    button.font = UIFont(name: "Avenir Next", size: 14)
    button.backgroundColor = UIColor.lightGrayColor()
    self.view.addSubview(button)
}

func buttonClick(Sender: UIButton!)
{
    myLabelInfo.text = "Hello"
}
Run Code Online (Sandbox Code Playgroud)

对于Swift方法,例如func buttonClick(Sender: UIButton)传递给addTarget选择器方法的正确字符串是什么?是"buttonClick","buttonClick:","buttonClickSender:"还是其他什么?

ios swift

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

如何检测UITextView中的链接是否已被点击,Swift

我已经实现了我认为UITextViewDelegate中的函数,它处理在UITextView中被点击的URL,但现在在我的代码中调用了函数.

这是我从代表处使用的功能.

func textView(textView: UITextView!, shouldInteractWithURL URL: NSURL!, inRange characterRange: NSRange) -> Bool {

println("Link Selected!")

}
Run Code Online (Sandbox Code Playgroud)

但是我使用了断点,甚至在运行时都没有访问代码?这是正确的功能还是有其他选择?

ios swift

6
推荐指数
1
解决办法
4345
查看次数

UIAlertController EXC_BAD_ACCESS错误 - Swift

我试图在iOS 7中使用Swift中的UIAlertController,当警报出现时我不断收到以下错误:EXC_BAD_ACCESS(code = 1,address = 0x10)

这是警报的代码.

var alert:UIAlertController = UIAlertController(title: "Ooops", message: "Please Fill In Everything", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        self.presentViewController(alert, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

ios swift uialertcontroller

5
推荐指数
1
解决办法
1415
查看次数

Xcode 6 Beta工具链错误

我正在尝试编译我正在处理的应用程序的一些代码并在iPhone上运行它,但每次运行它时,构建都会失败,这就是错误:

/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-stdlib-tool failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

它在两天前工作得很好,我不知道如何解决它.

iphone xcode

5
推荐指数
1
解决办法
4618
查看次数

如何用Swift iOS监听UIReturnKeyType.Next

当用户按下键盘上的下一个时,我想从当前的UITextField移动到下一个UITextField,UIReturnKeyType设置为UIReturnKeyType.Next

这是我如何设置UITextField.

username.returnKeyType = UIReturnKeyType.Next
username.textColor = UIColor.whiteColor()
username.placeholder = "Username"
username.borderStyle = UITextBorderStyle.RoundedRect
uUsername.textAlignment = NSTextAlignment.Center
username.backgroundColor = UIColor.lightGrayColor()
username.font = UIFont(name: "Avenir Next", size: 14)
username.autocapitalizationType = UITextAutocapitalizationType.None
username.autocorrectionType = UITextAutocorrectionType.No
Run Code Online (Sandbox Code Playgroud)

xcode ios swift

4
推荐指数
2
解决办法
8962
查看次数

PHP:为什么这个加法的答案是20而不是22?

为什么输出到20,而不是22?看到你正在添加10 + 0xA(HEX为10)+ 2.

$a = 010;
$b = 0xA;
$c = 2;

print $a + $b + $c;

Output: 20.
Run Code Online (Sandbox Code Playgroud)

php

4
推荐指数
1
解决办法
475
查看次数

如何使用Swift Code显示UITextField

我想在编译和运行应用程序时出现以下UITextField.我将UITextField声明并初始化为:

var myTextField: UITextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200.00, height: 40.00));
Run Code Online (Sandbox Code Playgroud)

但是,当我运行应用程序时,此文本字段不会出现.什么Swift代码会使文本字段出现?

ios swift

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

如何在iOS中使用Swift的属性占位符

我在函数调用中的最后一个参数有困难..

        myTextField.attributedPlaceholder = NSAttributedString(string: "Wage Type", attributes: NSForegroundColorAttributeName: ??????)
Run Code Online (Sandbox Code Playgroud)

我不知道如何使用此方法设置占位符的颜色.

ios swift

3
推荐指数
1
解决办法
3631
查看次数

通过Swift,iOS中的代理在类之间共享数据

我试图了解代理如何在Swift中更好地工作,总的来说.在我创建的示例中,我有一个Sender类和一个Receiver类.我想发送一条消息SenderReceiver

然后我想创建一个Receiver类的变量实例并打印Sender发送给它的消息.但是我遇到了困难,因为当我ShareMessage(message: NSString)从我创建的变量实例调用函数时,var recieveMessage我必须输入另一个消息或字符串,我无法检索Sender类发送给它的消息.

这是我正在使用的代码.我不确定我问的是否正确,但我只是好奇我如何检索变量实例中的数据.

import UIKit

// Protocol to send message between classes.
protocol SendersMessageDelegate{

    func shareMessage(message: NSString)
}

// Class that sends the message
class Sender{

    // Create variable to hold message
    var sendersMessage: NSString = NSString()

    var delegate: SendersMessageDelegate? = Receiver()

    // Grab the message when initialized and send to delegate
    init(sendersMessage: NSString){

        self.sendersMessage = sendersMessage
        delegate?.shareMessage(sendersMessage)
    }          

}

//Class …
Run Code Online (Sandbox Code Playgroud)

delegates ios swift

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

标签 统计

ios ×8

swift ×8

xcode ×2

delegates ×1

iphone ×1

php ×1

uialertcontroller ×1