小编Ján*_*nos的帖子

NSRange到Range <String.Index>

我怎么能转换NSRangeRange<String.Index>斯威夫特?

我想使用以下UITextFieldDelegate方法:

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

textField.text.stringByReplacingCharactersInRange(???, withString: string)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

nsstring nsrange swift ios8

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

为什么UICollectionViewCell的出口是零?

我在Interface Builder中创建了一个自定义UICollectionViewCell,将它绑定到类上,然后当我想使用并将字符串设置为字符串上的标签时,tha label的值为nil.

override func viewDidLoad() {
    super.viewDidLoad()

    // Register cell classes
    self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls")
}

override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {

    var cell: LeftMenuCollectionViewCell
    cell = collectionView.dequeueReusableCellWithReuseIdentifier("ls", forIndexPath: indexPath) as LeftMenuCollectionViewCell
    println(cell.label) // <- this is nil, why??
    cell.label.text = "asd"

    return cell
}
Run Code Online (Sandbox Code Playgroud)

和子类细胞:

class LeftMenuCollectionViewCell: UICollectionViewCell {

    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var label: UILabel!
    @IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
}
Run Code Online (Sandbox Code Playgroud)

interface-builder ios uicollectionviewcell swift ios8

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

"@UpppplicationMain"是什么意思?

我刚创建了我的第一个Swift项目,在AppDelegate.swift一个类声明上面有一行 - 为什么它在那里?!

...
import UIKit
import CoreData

@UIApplicationMain // <- WHY IS IT HERE?
class AppDelegate: UIResponder, UIApplicationDelegate {
... 
Run Code Online (Sandbox Code Playgroud)

swift

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

如何在Swift中使用substringToIndex?

我在这一行遇到编译器错误:

UIDevice.currentDevice().identifierForVendor.UUIDString.substringToIndex(8)
Run Code Online (Sandbox Code Playgroud)

类型'String.Index'不符合协议'IntegerLiteralConvertible'

我的意图是得到子串,但是如何?

substring swift

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

应该如何在Swift中使用ChangeCharactersInRange?

我正在使用shouldChangeCharactersInRange作为使用动态类型搜索的一种方式.

但是我遇到了问题,在文本字段实际更新之前调用了更改角色的内容:

在Objective C中,我使用以下方法解决了这个问题:

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString * searchStr = [textField.text stringByReplacingCharactersInRange:range withString:string];

    return YES;
}
Run Code Online (Sandbox Code Playgroud)

但是,我试过在Swift中写这个:

func textField(textField: UITextField!, shouldChangeCharactersInRange range: NSRange, replacementString string: String!) -> Bool {
    let txtAfterUpdate:NSString = self.projectSearchTxtFld.text as NSString
    txtAfterUpdate.stringByReplacingCharactersInRange(range, withString: string)

    self.callMyMethod(txtAfterUpdate)
    return true
}
Run Code Online (Sandbox Code Playgroud)

在得到值之前,该方法仍会被调用?

objective-c ios nsrange uitextfielddelegate swift

67
推荐指数
4
解决办法
6万
查看次数

将图像添加到uitableview单元格

我有一个tableview,我怎么能在这个单元格的左边添加图像?

uitableview uikit uiimage ios

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

在Swift中,我可以使用元组作为字典中的键吗?

我想知道我是否能以某种方式使用x,y对作为我字典的关键

let activeSquares = Dictionary <(x: Int, y: Int), SKShapeNode>()
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

Cannot convert the expression's type '<<error type>>' to type '$T1'
Run Code Online (Sandbox Code Playgroud)

和错误:

Type '(x: Int, y: Int)?' does not conform to protocol 'Hashable'
Run Code Online (Sandbox Code Playgroud)

那么..我们怎样才能使它符合要求?

dictionary tuples swift

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

类型“{}”不可分配给类型“ReactNode”

我收到此错误,但仅在 Vercel 中,而不是本地,为什么?

error: 'FontAwesomeIcon' cannot be used as a JSX component.
Run Code Online (Sandbox Code Playgroud)
./components/Services/ServiceContainer.tsx:25:6
12:01:54.967    Type error: 'FontAwesomeIcon' cannot be used as a JSX component.
12:01:54.967      Its element type 'ReactElement<any, any> | Component<FontAwesomeIconProps, any, any>' is not a valid JSX element.
12:01:54.968        Type 'Component<FontAwesomeIconProps, any, any>' is not assignable to type 'Element | ElementClass'.
12:01:54.968          Type 'Component<FontAwesomeIconProps, any, any>' is not assignable to type 'ElementClass'.
12:01:54.968            The types returned by 'render()' are incompatible between these types.
12:01:54.968              Type 'React.ReactNode' is not …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs next.js vercel

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

Swift中Int和Int32有什么区别?

Core Data你可以存储Int16,Int32,Int64但它是从不同的Int.它们存在的原因是什么,你如何使用它们?

int ios swift

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

如何删除CloudKit容器?

我不小心在CloudKit中创建了一个新的容器,当我打开仪表板时,它真的很烦人.有什么建议删除吗?在developer.apple.com上,我没有看到容器的删除按钮.

dashboard icloud cloudkit

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