小编CAN*_*CAN的帖子

格式化Swift中的电话号码

一旦用户开始在这种格式类型中输入电话号码,我就会格式化我的文本文本,0 (555) 444 66 77并且它工作正常但是一旦我从服务器获得号码,我就这样得到它05554446677所以请你告诉我如何编辑它一旦我从服务器上获取相同的格式?

我开始输入后的代码:

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

    if textField == phoneNumberTextField{
        var newString = (textField.text as NSString).stringByReplacingCharactersInRange(range, withString: string)
        var components = newString.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet)

        var decimalString = "".join(components) as NSString
        var length = decimalString.length
        var hasLeadingOne = length > 0 && decimalString.characterAtIndex(0) == (1 as unichar)

        if length == 0 || (length > 11 && !hasLeadingOne) || length > 12{
            var newLength = (textField.text as NSString).length …
Run Code Online (Sandbox Code Playgroud)

string string-formatting uitextfield ios swift

27
推荐指数
7
解决办法
4万
查看次数

重新加载tableView部分而不重新加载标题部分 - Swift

我正在尝试重新加载tableView部分而不是重新加载整个tableview,因为我在标题部分有一个文本字段,当我调用self.tableView.reloadData()我的键盘时关闭.

我已经尝试了下面的代码但是我收到了这个错误Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 5 from section 2 which only contains 4 rows before the update'所以请问我的问题在哪里?

    let newCount = self.placeArray.count

    var newIndexPaths = NSMutableArray(capacity: newCount)

    for var i = 0 ; i < newCount ; i++ {
    var indexPath = NSIndexPath(forRow: i, inSection: 2)
        newIndexPaths.addObject(indexPath)
    }

    self.tableView.beginUpdates()
    self.tableView.reloadRowsAtIndexPaths(newIndexPaths as [AnyObject], withRowAnimation: UITableViewRowAnimation.None)
    self.tableView.endUpdates()
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift

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

如何在Xcode 6中使用XIB创建iOS项目?

我正在尝试用Objective-C语言创建一个没有使用Xcode 6 Beta 5的故事板的项目.我尝试并创建了一个空项目,但它不能用作Xcode 5.

我已经阅读了这个主题如何在Xcode 6中创建没有故事板的项目 - Swift但它对我没有帮助.

objective-c ios

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

更改UIBarButtonItem文本字体大小和颜色

我想知道如何更改文本字体BarButtonItem?虽然我无法设置setTitleTextAttributes

class TextfieldLogin : UITextField {

func INIT(){
    let numberToolbar = UIToolbar(frame: CGRectMake(0,0,320,50))
    numberToolbar.tintColor = UIColor.whiteColor()
    numberToolbar.barTintColor = UIColor(red: 155.0/255, green: 14.0/255, blue: 45.0/255, alpha: 1.0)

    numberToolbar.items = [
        UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil),
        UIBarButtonItem(title: "DONE", style: UIBarButtonItemStyle.Plain, target: self, action: "close"),
        UIBarButtonItem.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(18.0),NSForegroundColorAttributeName : UIColor.redColor(),NSBackgroundColorAttributeName:UIColor.blackColor()],
            forState: UIControlState.Normal)        ]

    numberToolbar.sizeToFit()

    }
}
Run Code Online (Sandbox Code Playgroud)

uibarbuttonitem ios swift

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

MapView内部自定义单元委托问题

我创建了一个带有mapView的单元格的tableview。我正在添加注释,并尝试在它们之间建立路由。我已经使用另一个视图控制器的相同代码进行了相同的操作,该代码工作正常,但在具有地图的tableview自定义单元中无法进行相同的操作。它没有进入viewForAnnotation或中rendererForOverlay。我已将mapDelegate启用到视图控制器。所以,请问我的问题在哪里?

let cell = tableView.dequeueReusableCellWithIdentifier("cell8") as! MapViewTableViewCell
cell.mapView.delegate = self //Tested didn't work
    cell.mapView.setRegion(cell.mapView.regionThatFits(MKCoordinateRegionMakeWithDistance(sourceLocation.placemark.coordinate, 1800, 1800)), animated: true)

    cell.calculateRoute(cell.endLocations, secondArray: cell.waypointLocations)

        for item in cell.endLocations {

           let annotation = MKPointAnnotation()
        annotation.coordinate = item.placemark.coordinate
            if cell.endLocations.indexOf(item) == 0 {
                annotation.title = "start"
            }
            else {
                annotation.title = "end"
            }
            cell.mapView.addAnnotation(annotation)
        }

        return cell
Run Code Online (Sandbox Code Playgroud)

我已经做了扩展地图

extension CarViewController : MKMapViewDelegate{

func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {

    if (annotation.title! == "start") {

        let pinAnnotation = MKPinAnnotationView(annotation: annotation, …
Run Code Online (Sandbox Code Playgroud)

uitableview mkmapview ios swift

5
推荐指数
0
解决办法
495
查看次数

TabBarController 添加自定义按钮不可点击问题

我在tabBarController上添加一个自定义按钮,并且该按钮变成在tabBarController上,当我在tabBarController内点击它时,它会被点击,它工作正常,但如果我点击tabBar外部的部分,它就不可点击。

在此输入图像描述

class CustomBar: UITabBarController, UITabBarControllerDelegate {

    func addButton() {

        mainBasketView.frame =  CGRect(x: self.view.frame.size.width / 2 - 30, y: -20, width: 58, height: 58)
        mainBasketView.basketButton.addTarget(self, action: #selector(self.btnNewMoment_Action), for: UIControlEvents.touchUpInside)
        tabBar.addSubview(mainBasketView)
    }
}
Run Code Online (Sandbox Code Playgroud)

我不想添加它,view.addSubView因为当我调用时视图不会消失hidesBottomBarWhenPushed

uitabbarcontroller uitabbar ios swift

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

在UIPickerView问题中选择第一行

我有一个文本框多和pickerViewtoolBar它有一个done button.我的问题是我无法从选择器中选择第一行.虽然我已在didSelectRow中调试但它不会在其中运行.那么请问我的问题在哪里?

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    var value = currentPickerArray[row]
    textFieldOutletArray[currentTag].text = value
}
Run Code Online (Sandbox Code Playgroud)

uipickerview ios swift

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