我正在努力弄清楚这段代码的错误.这目前在Objective-C中工作,但在Swift中,这只是在方法的第一行崩溃.它在控制台日志中显示错误消息:Bad_Instruction.
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
var cell : UITableViewCell = tableView.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
if (cell == nil) {
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "Cell")
}
cell.textLabel.text = "TEXT"
cell.detailTextLabel.text = "DETAIL TEXT"
return cell
}
Run Code Online (Sandbox Code Playgroud) 我需要找到一个解决方案来解决Swift超级棒的"Source Kit Crashing"错误.我已经阅读了很多堆栈溢出帖子,但似乎没有人有解决方案.如果有一行代码导致问题,我无法通过捕获50 +源文件找到它.有没有人有这个问题的解决方案?
Xcode基本上和记事本一样有用,它已经变得如此糟糕.请有人有解决方案:).每次我在任何文件中键入一个字母时,Source Kit都会崩溃.
包含的框架:Parse,Layer,Fabric,各种苹果框架
注意:我的应用程序编译并运行完全正常
我试图简单地将UIView添加到占据整个单元框架的UICollectionViewCell.我现在的代码只在左上角显示一个单元格(我怀疑每个单元格在彼此的顶部进行分层).我怎么能这样做?
我计划稍后再继承UIView,以便自定义我添加到单元格的视图.我不想基于我将使用它的方式继承UICollectionViewCell.
#pragma mark - Collection view data source
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UIView *menuItem = [[UIView alloc] init];
menuItem.frame = cell.frame;
menuItem.backgroundColor = [UIColor greenColor];
[cell addSubview:menuItem];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath; {
return CGSizeMake(60, 60);
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以使UITableView的一部分的高度页眉/页脚等于页眉/页脚标题文本的高度.任何提示都会很棒!
注意:我的TableView的某些部分可能没有页眉/页脚,在这种情况下,只有部分之间有填充,因为在这种情况下"headerTitleHeight/footerTitleHeight"将为零.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return headerTitleHeight + padding;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return footerTitleHeight + padding;
}
Run Code Online (Sandbox Code Playgroud) 我有一个我正在创建的消息传递屏幕,我差不多完成了它.我使用nib文件和约束构建了大多数视图.我有一个小bug,但是当键盘解散时,我可以直观地看到一些单元格出现,因为需要在涉及约束的动画块中调用[self.view layoutIfNeeded].这是问题所在:
- (void)keyboardWillHide:(NSNotification *)notification
{
NSNumber *duration = [[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey];
NSNumber *curve = [[notification userInfo] objectForKey:UIKeyboardAnimationCurveUserInfoKey];
[UIView animateWithDuration:duration.doubleValue delay:0 options:curve.integerValue animations:^{
_chatInputViewBottomSpaceConstraint.constant = 0;
// adding this line causes the bug but is required for the animation.
[self.view layoutIfNeeded];
} completion:0];
}
Run Code Online (Sandbox Code Playgroud)
如果需要在视图上直接调用布局是否有任何方法,因为这也会导致我的集合视图自行布局,这有时会使单元格在屏幕上可视化.
我尝试了所有我能想到的但是我无法找到错误修复的解决方案.我已经尝试过调用[cell setNeedLayout]; 在每个可能的位置,没有任何反应.
uiviewanimation ios autolayout uicollectionview nslayoutconstraint
有人试过在swift中使用外观代理吗?
这个语法不起作用,有没有人想出如何在segmentedControl或UITabBar等控件上设置标题文本属性?我想我很亲密
segmentedControl.titleTextAttributesForState(UIControlState.Normal) =
NSDictionary(objects: [UIFont(name: fontFamilyRegular, size: 16.0)],
forKeys: [NSFontAttributeName])
Run Code Online (Sandbox Code Playgroud) 我正在观看WWDC2014上的一些视频并尝试编写我喜欢的代码,但我注意到的一个奇怪的事情是Swift一直对我生气并希望我投射到不同的数字类型.这很容易,但在WWDC的视频中他们不需要这样做.以下是"Interface Builder的新功能"中的示例:
-M_PI/2一直给我错误:"无法找到接受提供的参数的'/'的重载'
有没有人有这个问题的解决方案,这不仅仅涉及投射,因为有明显的另一种方式这样做?对于类似的问题,我有很多例子.
if !ringLayer {
ringLayer = CAShapeLayer()
let innerRect = CGRectInset(bounds, lineWidth / 2.0, lineWidth / 2.0)
let innerPath = UIBezierPath(ovalInRect: innerRect)
ringLayer.path = innerPath.CGPath
ringLayer.fillColor = nil
ringLayer.lineWidth = lineWidth
ringLayer.strokeColor = UIColor.blueColor().CGColor
ringLayer.anchorPoint = CGPointMake(0.5, 0.5)
ringLayer.transform = CATransform3DRotate
(ringLayer.transform, -M_PI/2, 0, 0, 1)
layer.addSublayer(ringLayer)
}
ringLayer.frame = layer.bounds
Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×4
ios8 ×2
objective-c ×2
uitableview ×2
autolayout ×1
sourcekit ×1
xcode ×1
xcode6 ×1
xcode6.1 ×1