小编Tap*_*Pal的帖子

Swift-3错误:' - [_ SwiftValue unsignedIntegerValue]:无法识别的选择器

以下代码与旧swift完美配合.这是String的扩展

func stringByConvertingHTML() -> String {
    let newString = replacingOccurrences(of: "\n", with: "<br>")
    if let encodedData = newString.data(using: String.Encoding.utf8) {
        let attributedOptions : [String: AnyObject] = [
            NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType as AnyObject,
            NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 as AnyObject
        ]
        do {
            let attributedString = try NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil) //Crash here
            return attributedString.string
        } catch {
            return self
        }
    }
    return self
}
Run Code Online (Sandbox Code Playgroud)

但是在迅速的3中,它崩溃了

***由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [_ SwiftValue unsignedIntegerValue]:无法识别的选择器发送到实例0x6080002565f0'

有人请建议我需要做什么?

xcode exception ios swift3

53
推荐指数
3
解决办法
9896
查看次数

以编程方式更新高度约束

我是汽车布局的新手.我已经完成了xib文件中的所有项目,但现在我遇到了一个问题,我必须以编程方式更新视图的高度.我试过下面但现在正在努力.

[[self view] addConstraint:[NSLayoutConstraint constraintWithItem:loginContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:loginFrame.size.height]];
Run Code Online (Sandbox Code Playgroud)

在控制台中显示

Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property …
Run Code Online (Sandbox Code Playgroud)

objective-c ios autolayout nslayoutconstraint swift

50
推荐指数
5
解决办法
6万
查看次数

Swift 3错误:"另请参见"标注未显示

我刚刚将我的项目迁移到swift 3中,发现"看到"的快速帮助标注没有显示出来.在以前版本的swift中,一切都完美无缺.以下是我的代码

/**
 Adds a See also callout to the Quick Help for a symbol using the See Also delimiter. Multiple See also callouts appear in the description section in the same order as they do in the markup..

 - author: Tapas Pal

 - remark: Use the callout to add references to other information.

 - seealso: [The Swift Standard Library Reference](https://developer.apple.com/library/prerelease/ios//documentation/General/Reference/SwiftStandardLibraryReference/index.html)

 */
class SeeAlsoMarkup: NSObject {
    static func doSomething() {}
}
Run Code Online (Sandbox Code Playgroud)

输出就像

在此输入图像描述

Apple是否通过此标记更改了任何内容?但是它的文档仍然显示相同.

code-documentation ios swift3 xcode8

25
推荐指数
2
解决办法
1183
查看次数

错误:UITableView使用UITableViewAutomaticDimension跳转到顶部

我使用UITableViewestimatedRowHeightUITableViewAutomaticDimension.我也用它NSFetchedResultsControllerDelegate来反映变化.

一切都很好.现在的问题是,当我添加一些记录时CoreData,NSFetchedResultsController称为它的委托,但意外的事情发生.每次TableView突然滚动到Top.

NSFetchedResultsControllerDelegate

func controllerWillChangeContent(controller: NSFetchedResultsController) {
    tableView.beginUpdates()
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
    tableView.endUpdates()
}

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
        switch type {
        case .Insert:
            tableView.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .None)
            break

        case .Update:
            tableView.reloadRowsAtIndexPaths([indexPath!], withRowAnimation: .None)
            break

        case .Delete:
            tableView.deleteRowsAtIndexPaths([indexPath!], withRowAnimation: .None)
            break

        default: break;
        }
    }
Run Code Online (Sandbox Code Playgroud)

通过谷歌搜索我发现很少有人建议使用的答案,tableView: heightForRowAtIndexPath:但因为我的细胞高度是动态的.所以我该怎么做?

core-data uitableview ios swift uitableviewautomaticdimension

17
推荐指数
2
解决办法
2360
查看次数

self.view.bounds.size.width返回错误的值

我现在面临一个非常奇怪的问题.获取[[self view] bounds].size.width总是320它不是根据设备改变.iPhone 5,6和6 Plus适用320.000000于所有方法.

- (void)viewDidLoad 
{
    [super viewDidLoad];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"%f", [[self view] bounds].size.width);
}
Run Code Online (Sandbox Code Playgroud)

产量

2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000 
2015-02-11 14:48:03.274 MyApp[2948:86285] 320.000000
2015-02-11 14:48:03.783 MyApp[2948:86285] 320.000000
Run Code Online (Sandbox Code Playgroud)

即使是闪屏也在那里.

如何获得视图的实际大小?

iphone objective-c bounds

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

Swift 3.0迁移错误:键入'Element'约束为非协议类型'IndexPath'

我正在尝试使用xCode将我的代码库迁移到swift 3.0.我无法理解的问题很少.

问题: Type 'Element' constrained to non-protocol type 'IndexPath'

在此输入图像描述

在错误导航面板的左侧,它仅显示错误.我无法理解哪行代码或代码分支导致错误.

在此输入图像描述

任何人都可以帮我解决这个问题.

UPDATE

经过艰苦的努力,我陷入了这些问题.

在此输入图像描述

UPDATE

感谢大家的帮助.现在我只面临以下问题.

在此输入图像描述

很少有人要求发布源代码,但Xcode没有在页面上显示任何类型的警告或错误.仿制药很少

private extension Array where Element: IndexPath {

    func indexOf(_ indexPath: IndexPath) -> Int {
        var counter = 0
        for object in self {
            if object.section == indexPath.section && object.row == indexPath.row {
                return counter
            }
            counter += 1
        }
        return 0
    }
}


fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  switch (lhs, rhs) {
  case let (l?, r?): …
Run Code Online (Sandbox Code Playgroud)

migration ios swift swift3

15
推荐指数
1
解决办法
7736
查看次数

无法从路径上的bundle加载Info.plist

我正在使用xcode 8.2.1.第一次或刚从模拟器中删除应用程序后,它工作正常.但是从第二次我得到以下错误!

在此输入图像描述

我尝试从以下链接解决我的问题,但这些也不适合我.

无法从捆绑包加载Info.plist

无法在模拟器中运行应用程序:Xcode beta 6 iOS 8

还有其他方法吗?

ios xcode8.2

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

放大后MapView叠加层将被切断

我面临着一个奇怪的问题MKMapView.我用了一个MKOverlayRenderer.现在的问题是当我缩小图像显示正确时.但是在放大的情况下,图像的某些部分会被切断.它看起来像MapView覆盖层上方的一部分.以下是我的叠加渲染器代码.

class MapOverlayRenderer: MKOverlayRenderer {
    var overlayImage: UIImage
    var plan: Plan

    init(overlay: MKOverlay, overlayImage: UIImage, plan: Plan) {
        self.overlayImage = overlayImage
        self.plan = plan
        super.init(overlay: overlay)
    }

    override func draw(_ mapRect: MKMapRect, zoomScale: MKZoomScale, in ctx: CGContext) {
        let theMapRect = overlay.boundingMapRect
        let theRect = rect(for: theMapRect)

        // Rotate around top left corner
        ctx.rotate(by: CGFloat(degreesToRadians(plan.bearing)));

        // Draw the image
        UIGraphicsPushContext(ctx)
        overlayImage.draw(in: theRect, blendMode: CGBlendMode.normal, alpha: 1.0)
        UIGraphicsPopContext();
    }

    func degreesToRadians(_ x:Double) -> Double { …
Run Code Online (Sandbox Code Playgroud)

cgcontext mkmapview mkoverlay cgcontextdrawimage swift3

8
推荐指数
1
解决办法
205
查看次数

UIScrollView:键盘以交互方式解除

在此输入图像描述

在上面的图像中,顶部栏是一个自定义视图,我使用像应用程序的应用程序.键盘将使用UIScrollView以交互方式解除.我已经实现UIKeyboardWillHideNotificationUIKeyboardDidChangeFrameNotification上下移动该视图.现在的问题是因为我使用的键盘将以交互方式解除,因此当用户将手指拖动到键盘时,它会相应地向上或向下移动.但我也无法获得任何类型的通知来上下移动视图.

notifications uiscrollview uikeyboard ios swift

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

Kenburner Slider无法在IE中工作

目前我在网站上工作,我在主页上使用了Kenburner Slider.

Slider在Firefox和Chrome上运行良好,但它不适用于IE7及更低版本.任何人都可以建议我应该采取什么措施?

jquery cross-browser

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