小编use*_*641的帖子

AutoLayout适用于ios 8但不适用于ios 7吗?

我在UICollectionViewCell中使用autolayout.超级简单的布局:只是一个UILabel.我希望UILabel占据整个宽度减去20像素的插入,并在垂直和水平方向上居中.我设置了那样做的约束.如果我在任何ios 8设备或模拟器上运行它,它可以很好地工作.但是,当我在某些ios 7设备上运行时,约束无效.我试着浏览一下苹果文档,但他们的改动似乎都不是围绕自动布局.

这是XML源代码,但我怀疑它意味着什么:

<constraints>
            <constraint firstItem="OIc-cg-9hO" firstAttribute="leading" secondItem="Ga6-nx-lOn" secondAttribute="leading" constant="20" id="A7U-sd-fcL"/>
            <constraint firstAttribute="centerY" secondItem="OIc-cg-9hO" secondAttribute="centerY" id="G9e-9W-aDS"/>
            <constraint firstAttribute="centerX" secondItem="OIc-cg-9hO" secondAttribute="centerX" id="TrB-hI-7Kw"/>
            <constraint firstAttribute="trailing" secondItem="OIc-cg-9hO" secondAttribute="trailing" constant="20" id="yjH-nf-D9U"/>
        </constraints>
Run Code Online (Sandbox Code Playgroud)

更多的解决方法而不是答案:但我在代码中添加了约束,如下所示:

    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
                                                      attribute:NSLayoutAttributeWidth
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self
                                                      attribute:NSLayoutAttributeWidth
                                                     multiplier:1.0
                                                       constant:-20.0]];

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
                                                      attribute:NSLayoutAttributeCenterX
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self
                                                      attribute:NSLayoutAttributeCenterX
                                                     multiplier:1.0
                                                       constant:0.0]];

[self addConstraint:[NSLayoutConstraint constraintWithItem:self.cellName
                                                      attribute:NSLayoutAttributeCenterY
                                                      relatedBy:NSLayoutRelationEqual
                                                         toItem:self
                                                      attribute:NSLayoutAttributeCenterY
                                                     multiplier:1.0
                                                       constant:0.0]];
Run Code Online (Sandbox Code Playgroud)

为了使它工作,我需要编码约束和IB约束.不知道为什么!

objective-c ios ios7 ios8

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

isEqualToString为相同的字符串返回false?

也许我疯了,但我似乎无法理解为什么isEqualToString在这种情况下返回false.

我编写了以下方法来解码百分比编码的URL中的字符串:

-(NSString*) decodeFromURLSafe: (NSString*) urlToDecode{
    NSString *safeUrl = [urlToDecode stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    safeUrl = [safeUrl stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    return safeUrl;
}
Run Code Online (Sandbox Code Playgroud)

在实践中它可行,但我为它写了一些测试,并不明白为什么它们失败了

这是一个这样的测试:

-(void)testDecodingFromURLSafe{
    NSString *unescapedString = @"@a!b*c(d)e;f:g&h=i+j$k,l/m#n\\p[q]r<s>t^u{v}w|x~y";
    NSString *answer = [_viewController decodeFromURLSafe:@"%40a%21b%2Ac%28d%29e%3Bf%3Ag%26h%3Di%2Bj%24k%2Cl%2Fm%23n%5C%5Cp%5Bq%5Dr%3Cs%3Et%5Eu%7Bv%7Dw%7Cx%7Ey"];
    NSLog(@"%@", answer);
    NSLog(@"%d", [answer isEqualToString:@"@a!b*c(d)e;f:g&h=i+j$k,l/m#n\\p[q]r<s>t^u{v}w|x~y"]);
    XCTAssert([answer isEqualToString:unescapedString], @"decoding works");
}  
Run Code Online (Sandbox Code Playgroud)

第二个NSLog语句中的字符串直接从第一个输出中复制:

2014-11-20 14:03:46.352 ProjName[5573:60b] @a!b*c(d)e;f:g&h=i+j$k,l/m#n\\p[q]r<s>t^u{v}w|x~y
Run Code Online (Sandbox Code Playgroud)

但是这两个比较都返回了错误,我对我所缺少的东西感到困惑.我已经尝试将字符串放入DiffNow中以仔细检查它们是否相同而且仍然没有.

objective-c ios

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

标签 统计

ios ×2

objective-c ×2

ios7 ×1

ios8 ×1