小编Phi*_*ott的帖子

如何以编程方式解雇UISearchBar?

我有一个标准的表视图,通过NIB实现UISearchController.我想模仿当用户点击搜索栏中的"取消"时会发生什么 - 正常的行为是搜索栏消失并且表格返回其原始状态.基本上,当用户选择出现在搜索结果中的项目时,我希望发生同样的事情.

当用户点击"取消"时,我找不到任何地方的过程.

iphone cocoa-touch

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

如何在iOS 8中获取UICollectionViewCells的自动布局大小?(systemLayoutSizeFittingSize在iOS 8中返回零高度的大小)

由于iOS 8 [UIColletionViewCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]返回高度为0的大小.

这是代码的作用:

为了确定UICollectionViewiOS 7中单元格的大小,我使用systemLayoutSizeFittingSize:自动布局在xib文件中定义的单元格上使用.大小取决于UILabel作为UICollectionViewCell我的xib文件中的子视图的字体大小.标签的字体设置为UIFontTextStyleBody.所以基本上单元格的大小取决于iOS 7中的字体大小设置.

这是代码本身:

+ (CGSize)cellSize {
    UINib *nib = [UINib nibWithNibName:NSStringFromClass([MyCollectionViewCell class]) bundle:nil];

    // Assumption: The XIB file only contains a single root UIView.
    UIView *rootView = [[nib instantiateWithOwner:nil options:nil] lastObject];

    if ([rootView isKindOfClass:[MyCollectionViewCell class]]) {
        MyCollectionViewCell *sampleCell = (MyCollectionViewCell*)rootView;
        sampleCell.label.text = @"foo"; // sample text without bar

        [sampleCell setNeedsLayout];
        [sampleCell layoutIfNeeded];

        return [sampleCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
    }

    return CGSizeZero;

}
Run Code Online (Sandbox Code Playgroud)

它在iOS 7中完美运行,但在iOS 8中运行不佳.不幸的是,我不知道为什么.

如何在iOS …

objective-c ios autolayout ios8

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

标签 统计

autolayout ×1

cocoa-touch ×1

ios ×1

ios8 ×1

iphone ×1

objective-c ×1