小编rul*_*ilg的帖子

致命错误:在解包可选值时意外发现nil

UICollectionView在Swift 中使用了一个,但是当我尝试更改单元格标签的文本时,我得到了.

    func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int
{
    return 5
}

func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell!
{
    var cell = collectionView.dequeueReusableCellWithReuseIdentifier("title", forIndexPath: indexPath) as TitleCollectionViewCell
    // Next line: fatal error: unexpectedly found nil while unwrapping an Optional value
    cell.labelTitle.text = "This is a title"
    return cell
}
Run Code Online (Sandbox Code Playgroud)

有谁知道这个?

控制台上警告的屏幕截图

ios uicollectionview swift

125
推荐指数
6
解决办法
25万
查看次数

Swift:来自Center的UIBezierPath Stroke动画

我一直UIBezierPath用Swift 做一个简单的动画.此路径包括创建带有彩色边框的圆角矩形.动画必须是彩色边框的绘图.为此,我创建了一个CAShapeLayer带有UIBezierPath(roundedRect:, cornerRadius: )

let layer = CAShapeLayer()
var viewPrueba = UIView()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    viewPrueba = UIView(frame: CGRectMake(self.view.frame.width/2-100, self.view.frame.height/2 - 100, 200, 200))
    self.view.addSubview(viewPrueba)
    let path = UIBezierPath(roundedRect: CGRectMake(0, 0, 200, 200), cornerRadius: 40.0)
    layer.path = path.CGPath
    layer.fillColor = UIColor.clearColor().CGColor
    layer.strokeColor = UIColor.blueColor().CGColor
    layer.strokeStart = 0.0
    layer.strokeEnd = 0.0
    layer.lineWidth = 4.0
    layer.lineJoin = kCALineJoinRound
    viewPrueba.layer.addSublayer(layer)
    let tapGR = …
Run Code Online (Sandbox Code Playgroud)

animation stroke ios uibezierpath swift

13
推荐指数
1
解决办法
2081
查看次数

Swift - 找不到重载...&无法转换表达式的类型

我正在适应Swift一种我在互联网上找到的ObjectiveC方法(可能在这里,我记不起来了)当我为iPad Air构建它时,它运行得很完美,但当我尝试在iPad 2或iPad上运行时Retina它给出4个错误(2个不同的错误,每个错误两次):

/* Scale and crop image */
func imageByScalingAndCroppingForSize(#originalImage: UIImage, size:CGSize) -> UIImage {
    let sourceImage = originalImage
    var newImage: UIImage
    let imageSize: CGSize = sourceImage.size
    let width: Double = Double(imageSize.width)
    let height: Double = Double(imageSize.height)
    var targetWidth: Double = Double(size.width)
    var targetHeight: Double = Double(size.height)
    var scaleFactor: Double = 0.0
    var scaledWidth: Double = targetWidth
    var scaledHeight: Double = targetHeight
    var thumbnailPoint: CGPoint = CGPointMake(0.0, 0.0)

    if (imageSize != size) {
        let widthFactor: Double = Double(targetWidth / …
Run Code Online (Sandbox Code Playgroud)

overloading cgfloat ios swift

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

Swift - 获取国家/地区列表

如何在Swift中获取包含所有国家/地区名称的数组?我试图转换Objective-C中的代码,这是:

if (!pickerCountriesIsShown) {
    NSMutableArray *countries = [NSMutableArray arrayWithCapacity: [[NSLocale ISOCountryCodes] count]];

    for (NSString *countryCode in [NSLocale ISOCountryCodes])
    {
        NSString *identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: countryCode forKey: NSLocaleCountryCode]];
        NSString *country = [[NSLocale currentLocale] displayNameForKey: NSLocaleIdentifier value: identifier];
        [countries addObject: country];
    }
Run Code Online (Sandbox Code Playgroud)

在斯威夫特我无法从这里传递:

        if (!countriesPickerShown) {
        var countries: NSMutableArray = NSMutableArray()
        countries = NSMutableArray.arrayWithCapacity((NSLocale.ISOCountryCodes).count) // Here gives the Error. It marks NSLocale.ISOCountryCodes and .count
Run Code Online (Sandbox Code Playgroud)

你们有谁知道这个吗?

谢谢

arrays countries ios nslocale swift

5
推荐指数
2
解决办法
9656
查看次数

swift - 来自预先填充的SQLite的CoreData

我已经使用CoreData填充了一个数据库,现在我想在swift中将它用作我的应用程序中的默认数据库.我已经读过它,但我只在Objective-C中找到了教程,Xcode6在AppDelegate中创建的Core Data方法对我来说很奇怪......

这是代码:

    // MARK: - Core Data stack

lazy var applicationDocumentsDirectory: NSURL = {
    // The directory the application uses to store the Core Data store file. This code uses a directory named "RLopez.BORRAME" in the application's documents Application Support directory.
    let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
    return urls[urls.count-1] as NSURL
    }()

lazy var managedObjectModel: NSManagedObjectModel = {
    // The managed object model for the application. This property is not optional. It is a fatal error for the application …
Run Code Online (Sandbox Code Playgroud)

sqlite core-data ios swift

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

Swift - UIBezierPath调用中的额外参数'radius'

我正在调整Objective-C库(STKSpinnerView)到Swift,我无法解决这个错误:

func getRadius() -> CGFloat {
    var r : CGRect = CGRectInset(self.bounds, self.wellThickness/2.0, self.wellThickness/2.0)
    var w : CGFloat = r.size.width
    var h : CGFloat = r.size.height

    if w > h {
        return h/2.0
    }else{
        return w/2.0
    }
}

override func layoutSubviews()  {
    super.layoutSubviews()

    var bounds : CGRect = self.bounds
    var wt : CGFloat = self.wellThickness
    var outer : CGRect = CGRectInset(self.bounds, wt/2.0, wt/2.0)
    var inner : CGRect = CGRectInset(self.bounds, wt, wt)

    var innerPath : UIBezierPath = UIBezierPath(ovalInRect: inner) …
Run Code Online (Sandbox Code Playgroud)

layoutsubviews uibezierpath swift

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

应用程序试图在目标上推送一个nil视图控制器

我收到以下错误:

Application tried to push a nil view controller on target UINavigationController: 0x7b98940.

它是在我"点击"一个单元格时引起的UITableViewController.码:

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    VerifyInfoViewController *verifyInfoVC = [self.storyboard instantiateViewControllerWithIdentifier:@"verifyInfoVC"];
    [self.navigationController pushViewController:verifyInfoVC animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

push uitableview ios

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