标签: swift3

获取所有用户的联系电话号码Swift3/iOS9 +

我发现的大部分内容都是使用AddressBook而不是新的Contacts.我正在尝试将所有用户联系人的姓名和电话号码显示在应用程序的tableview中.然后将所有这些数字带入一个API,该API交叉引用是否已经有任何帐户,因此我可以在那些旁边显示"添加朋友"按钮.是否有一种快速简便的方法来请求权限然后使用Swift3将所有联系人放入一个数组并与iOS9和更新版本兼容?

我不想找到或添加联系人,我只想要一个数组中的所有数字和名称

swift cncontact cncontactstore swift3

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

尝试显示其视图不在具有本地通知的窗口层次结构中的UIAlertController

我试图在用户点击本地通知后呈现AlertView.AlertView具有取消或确定选项.

extension ViewController:UNUserNotificationCenterDelegate{


    func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

        print("Tapped in notification")
        if(defaults.object(forKey: "alertOn") != nil){


            // Create the alert controller
            let alertController = UIAlertController(title: "Some text", message: "Some text again", preferredStyle: .alert)


            // Create the actions
            let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
                UIAlertAction in

            }

            let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
                UIAlertAction in
            }

            // Add the actions
            alertController.addAction(okAction)
            alertController.addAction(cancelAction)

            // Present the controller
                self.present(alertController, animated: true, …
Run Code Online (Sandbox Code Playgroud)

ios swift swift3

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

如何获取当月的最后日期

我花了差不多一个星期尝试不成功.如何获取当月的最后日期.例如,如果它是非闰年的二月,那么该月的最后一个日期必须是28.如何获得'28'.另一个例子:如果是1月那么最后一个日期必须是'31'

swift swift3

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

自定义文本字段

嗨,我想建立一些看起来像图片的东西!

屏幕截图示例 我的问题是文本字段不能是两个部分,并在其中使用微小的图片就像一个图片我想做一些事情就像图片甚至每个文本字段右侧的绿色部分

这就是我想要做的

textfield ios swift3 xcode8.2

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

Firebase推送数据Swift?

我知道对于Web Firebase API,有一个.push()选项可以保证条目按照它们插入数据库的顺序.但是,使用Swift添加数据的唯一方法是使用.set().updateChildValues()方法.

是否有类似于.push()Swift的内容,我可以确保我的数据按插入顺序显示?

firebase swift firebase-realtime-database swift3

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

使用RXSwift的警报消息的UIViewController扩展

我正在UIViewcontroller使用alertmessage扩展程序进行使用RXSwift.

    // UIViewController+Alertmessage
        public func observeAlertMessageSignal(alert: Observable<String>) {
            let disposeBag = DisposeBag()

            alert.observeOn(MainScheduler.instance)
                .subscribe(onNext:  { message in
                    self.alertCustomTransitionDelegate = CustomTransitioningDelegate()

                    let viewModel = AlertViewModel(message: message)

                    let storyboard = UIStoryboard(name: "Alert", bundle: nil)
                    let viewController = storyboard.instantiateInitialViewController() as! AlertViewController
                    viewController.viewModel = viewModel
                    viewController.delegate = self
                    viewController.modalPresentationStyle = .custom
                    viewController.transitioningDelegate = self.alertCustomTransitionDelegate

                    self.present(viewController, animated: true, completion: nil)

            }).addDisposableTo(disposeBag)
        }

    // ViewModel

    --> Declaration of alertObservable in viewModel
        var alertObservable = PublishSubject<String>()

    --> usage of observable:
    transportResponse = active.asObservable() …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller ios swift rx-swift swift3

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

UITableView问题:Action每秒都有效

我有一个UITableViewController的问题:表视图显示但是只有在触摸单元格时才会调用didDeselectRowAt.有没有人看到这个代码的问题?

import UIKit
import MediaPlayer


class LibraryTableViewController: UITableViewController{
    let mediaItems = MPMediaQuery.songs().items


    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }


    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return mediaItems!.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)  
        cell.textLabel?.text = mediaItems?[indexPath.row].title      
        return cell
    }

    override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        print("table item selected")
        OperationQueue.main.addOperation{
            self.performSegue(withIdentifier: "showPlayer", sender: self)
        }
    }

    override func …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift3

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

警卫在Swift 3中的位置

在Swift 2中,我们可以轻松添加保护声明的位置

guard let varA = 1 where varB == 2 else {return}
Run Code Online (Sandbox Code Playgroud)

但是where在swift 3中删除了,我怎么能在Swift 3中做到这一点?

swift3

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

Swift 3:将字符附加到数组

我有一个使用以下内容初始化的Swift 3数组:

var foo: [String] = []

在我的一个递归调用的方法中,我试图将一个字符串转换为一个字符数组,但是附加这些字符而不是直接赋值foo.所以这将编译:

self.foo = text.characters.map { String($0) }

但是下面的休息:

self.foo.append(text.characters.map { String($0) })

它产生的错误是: 'map' produces '[T]', not expected contextual result type 'String'

接近这个的正确方法是什么?

swift swift3

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

如何防止UILabel在Swift中阻止对父UIButton的触摸?

我有一个UIButton,它有四个子UILabel,包含有关按钮功能的信息.当我单击按钮的中心时,操作不会触发,因为它被UILabel阻挡,但当我单击按钮外部时,操作会触发.有没有办法阻止UILabels阻止动作射击?

uibutton uilabel ios swift swift3

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