在我更新xCode 6之前,我没有任何问题将一个double转换为字符串bur现在它给了我错误
var a: Double = 1.5
var b: String = String(a)
Run Code Online (Sandbox Code Playgroud)
它给我错误消息"double不能转换为字符串".还有其他办法吗?
我试图tableView
使用以下代码将每行的高度设置为相应单元格的高度:
override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
var cell = tableView.cellForRowAtIndexPath(indexPath)
return cell.frame.height
}
Run Code Online (Sandbox Code Playgroud)
初始化时出现此错误var cell
:
线程1:EXC_BAD_ACCESS(代码= 2,地址= 0x306d2c)
当我尝试从"用户"类查询所有用户时遇到一些奇怪的问题它找不到任何用户
var query:PFQuery=PFQuery(className: "User");
query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]!, error: NSError!) -> Void in
if !(error != nil) {
for(var i=0;i<objects.count;i++){
var object=objects[i] as PFObject;
var name = object.objectForKey("username") as String;
println(name);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试过更换
var query:PFQuery=PFQuery(className: "User");
Run Code Online (Sandbox Code Playgroud)
同
var query:PFQuery=PFQuery(className: "AnotherClass");
Run Code Online (Sandbox Code Playgroud)
一切都像我应该的那样奏效.我认为对于"用户"类来说一定是特别的
当你从另一个viewController呈现一个viewController时,你会这样做:
let vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier("viewController") as UIViewController;
self.presentViewController(vc, animated: true, completion: nil);
Run Code Online (Sandbox Code Playgroud)
我想从SKScene呈现一个viewController.我没有找到任何办法.这个问题可能是重复的,但我刚刚在客观C中找到了对我没有意义的答案
UICollectionView的标头显示不正确.我在标题中添加了一个UILabel,它应该显示节号.当我调试viewForSupplementaryElementOfKind时,一切看起来都没问题.我查看了有关collectionView标头的不同教程,我在代码中找不到错误.
这是整个代码:
import UIKit
class ViewController: UIViewController {
var collectionView:UICollectionView!;
override func viewDidLoad() {
super.viewDidLoad()
let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout();
layout.sectionInset = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20);
layout.itemSize = CGSize(width: 60, height: 60);
layout.headerReferenceSize = CGSize(width: CGRectGetWidth(self.view.bounds), height: 50);
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout);
collectionView.dataSource = self;
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "cell");
collectionView.registerClass(UICollectionReusableView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "header");
collectionView.delegate = self;
self.view.addSubview(collectionView);
}
}
extension ViewController:UICollectionViewDataSource{
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5;
}
func numberOfSectionsInCollectionView(collectionView: …
Run Code Online (Sandbox Code Playgroud) swift ×5
casting ×1
double ×1
ios ×1
pfquery ×1
skscene ×1
sprite-kit ×1
string ×1
uitableview ×1
xcode ×1