小编Hex*_*ire的帖子

如何隐藏UINavigationBar 1px底线

我有一个应用程序,有时需要其导航栏与内容融为一体.

有谁知道如何摆脱或改变这个讨厌的小酒吧的颜色?

在下面的图像我有 - 我正在谈论"根视图控制器"下面这个1px高度线

在此输入图像描述

objective-c uinavigationbar ipad ios swift

422
推荐指数
21
解决办法
17万
查看次数

UICollectionView的动态单元格宽度取决于标签宽度

我有一个UICollectionView,它从可重用的单元格加载单元格,其中包含标签.数组为该标签提供内容.我可以使用sizeToFit轻松调整标签宽度,具体取决于内容宽度.但我不能让细胞贴合标签.

这是代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    arrayOfStats =  @[@"time:",@"2",@"items:",@"10",@"difficulty:",@"hard",@"category:",@"main"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:     (NSInteger)section{
    return [arrayOfStats count];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    return CGSizeMake(??????????);
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    Cell *cell = (Cell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"qw" forIndexPath:indexPath];
    cell.myLabel.text = [NSString stringWithFormat:@"%@",[arrayOfStats objectAtIndex:indexPath.item]];
    // make label width depend on text width
    [cell.myLabel sizeToFit];

    //get the width …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell swift

80
推荐指数
7
解决办法
7万
查看次数

不支持推送导航控制器

在我的MainStoryBoard中,我想将viewController推送到detailView,但是我收到此错误:

NSInvalidArgumentException',原因:'不支持推送导航控制器'

我在故事板上为viewController设置了标识符'JSA'ID.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        SWSJSAViewController *viewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"JSA"];
        [self.navigationController pushViewController:viewController animated:YES];
    }
}
Run Code Online (Sandbox Code Playgroud)

objective-c storyboard uinavigationcontroller ios swift

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

Swift同时将对象转换为类型和协议

如何将给定对象强制转换为类型和协议,以便调用某些定义为扩展名的方法

例如:

extension Identifiable where Self: NSManagedObject, Self: JsonParseDescriptor {
    func someMethod() { }
}
Run Code Online (Sandbox Code Playgroud)

现在我有一个从Core数据中检索到的对象,我想将它转换为上述协议,以便在其上调用someMethod.我可以使用转换为协议protocol<Identifiable, JsonParseDescriptor>,但是如何在其中包含NSManagedObejct类型呢?

谢谢

core-data ios swift swift-protocols swift3

8
推荐指数
2
解决办法
1632
查看次数

Matplotlib在我全部运行时没有显示在Jupyter笔记本上

当图表不显示内联 - >%matplotlib笔记本

这些图显示为完全空白.有任何想法吗?

看到这里

python matplotlib jupyter-notebook

7
推荐指数
2
解决办法
4274
查看次数

如何检查对象是否为集合?(迅速)

我广泛使用KVC构建满足应用程序需求的统一界面。例如,我的一个函数获取了一个对象,该对象仅基于字符串键字典进行几次检查。

因此,我需要一种方法来检查键对象是否为集合类型。

我希望能够进行一些协议检查(例如C#中的IEnumerable来检查它是否可以枚举),但是没有成功:

if let refCollection = kvcEntity.value(forKey: refListLocalKey) as? AnySequence<CKEntity> { ... }
Run Code Online (Sandbox Code Playgroud)

我也尝试过AnyCollection。

我知道我可以通过键入以下内容来迭代所有主要集合类型:

if let a = b as? Set { ...} // (or: if a is Set {...})
if let a = b as? Array { ...}
if let a = b as? Dictionary { ...}
Run Code Online (Sandbox Code Playgroud)

但这从继承/多态性的角度来看似乎不合适。

generics collections swift

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