小编Zev*_*erg的帖子

在ObjectiveC中从NSDictionary对象创建URL查询参数

由于所有的URL处理对象都位于标准的Cocoa库(NSURL,NSMutableURL,NSMutableURLRequest等)中,我知道我必须忽略一种以编程方式编写GET请求的简单方法.

目前我手动追加"?" 后跟由"&"连接的名称值对,但我的所有名称和值对都需要手动编码,因此NSMutableURLRequest在尝试连接到URL时不会完全失败.

这感觉就像我应该能够使用预先出炉的API ......是否有任何开箱即可将查询参数的NSDictionary附加到NSURL?我还有另一种方法吗?

objective-c nsurl

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

UICollectionView水平分页 - 我可以使用Flow Layout吗?

这与"使用流程布局"或"自定义"有何不同?.

以下是我正在尝试做的事情的说明: 我想要做的插图

我想知道我是否可以使用它UICollectionViewFlowLayout的子类,或者如果我需要创建一个完全自定义的布局?根据UICollectionView上的WWDC 2012视频,如果您使用垂直滚动的Flow Layout,您的布局线条是水平的,如果您水平滚动,您的布局线条是垂直的.我想在水平滚动的集合视图中使用水平布局线.

我的模型中也没有任何固有的部分 - 这只是一组项目.我可以将它们分成几个部分,但是集合视图是可调整大小的,因此可以适应页面的项目数量有时会发生变化,看起来每个项目所在的页面的选择最好留给布局而不是如果我没有任何有意义的部分,该模型.

那么,我可以使用Flow Layout执行此操作,还是需要创建自定义布局?

uikit ios uicollectionview uicollectionviewlayout

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

集合视图中的单元格中的UIButton未在事件内部接收修饰

下面的代码表达了我的问题:(它是自包含的,你可以创建一个带有空模板的Xcode项目,替换main.m文件的内容,删除AppDelegate.h/.m文件并构建它)

//
//  main.m
//  CollectionViewProblem
//


#import <UIKit/UIKit.h>

@interface Cell : UICollectionViewCell

@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UILabel *label;

@end

@implementation Cell
 - (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.label = [[UILabel alloc] initWithFrame:self.bounds];
        self.label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.label.backgroundColor = [UIColor greenColor];
        self.label.textAlignment = NSTextAlignmentCenter;

        self.button = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
        self.button.frame = CGRectMake(-frame.size.width/4, -frame.size.width/4, frame.size.width/2, frame.size.width/2);
        self.button.backgroundColor = [UIColor redColor];
        [self.button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:self.label];
        [self.contentView addSubview:self.button];
    }
    return self;
}


// Overriding …
Run Code Online (Sandbox Code Playgroud)

uiresponder ios uicollectionview

23
推荐指数
4
解决办法
2万
查看次数

错误:在NSAttributedString扩展名中使用未声明的类型'$ __ lldb_context'

给出以下Swift代码,保存在bug.swift中,并使用Xcode 8.2.1或Xcode 8.3 beta 2:

import Foundation

protocol MyProtocol {
    func foo() -> String
}

extension MyProtocol {
    func foo() -> String {
        return "\(self)"
    }
}

extension String: MyProtocol {}
extension NSAttributedString: MyProtocol {}

let normal = "normal".foo()
let attributed = NSAttributedString(string: "attributed", attributes: [:]).foo()
Run Code Online (Sandbox Code Playgroud)

运行以下命令:

swiftc -g bug.swift
lldb bug
Run Code Online (Sandbox Code Playgroud)

LLDB启动.现在,运行这些命令,并观察输出.我通过的地方9,传递bug.swift包含的内容return "\(self)":

(lldb) target create "bug"
Current executable set to 'bug' (x86_64).
(lldb) b 9
Breakpoint 1: where = bug`(extension in bug):bug.MyProtocol.foo …
Run Code Online (Sandbox Code Playgroud)

lldb swift

16
推荐指数
1
解决办法
2636
查看次数

围绕UIView的一些角落并围绕视图的图层边界

我试图围绕UIView的底部两个角落,并且图层的边框也显示为圆形.我目前在做:

UIRectCorners corners = UIRectCornerBottomLeft | UIRectCornerBottomRight;
CGSize radii = CGSizeMake(kThisViewCornerRadius, kThisViewCornerRadius);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:myView.bounds
                                           byRoundingCorners:corners
                                                 cornerRadii:radii];

CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setPath:path.CGPath];
myView.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)

这适用于普通视图.然而,myView的一层都有borderColorborderWidth集,因为你从截图中可以看到,该层的边框是没有得到四舍五入:

问题的屏幕截图

我还尝试了子类化UIView并[CAShapeLayer layer]从中返回+[Class layerClass],并将视图的图层设置形状图层,但边框最终位于视图的子视图下方.

是否可以围绕视图的某些角落,围绕视图的图层边框,并将子视图剪切到图层边框下方?

请注意,这不是关于如何围绕某些角落而不是其他角落,而是如何使笔划正确行为.

objective-c calayer ios

15
推荐指数
2
解决办法
7291
查看次数

演示后在UIPresentationController中调整呈现视图的帧

我正在使用自定义演示控制器来制作类似的东西UIAlertView.我希望它在键盘显示时向上移动.在UIKeyboardWillShowNotification处理程序中,我抓住新的键盘框架,将其存储在属性中,然后调用:

self.presentedView.frame = [wself frameOfPresentedViewInContainerView];
Run Code Online (Sandbox Code Playgroud)

在我的实现中-frameOfPresentedViewInContainerView,我考虑了当前的键盘高度.

这很有效,但self.presentedView直接修改框架感觉有点脏.我试图与不同排列的容器视图触发布局setNeedsLayoutlayoutIfNeeded,但没有引起呈现视图的不仅仅是直接设置它的框架移动等.

有没有更好的方法来做到这一点,而不仅仅是自己改变框架?

cocoa-touch uikit ios uipresentationcontroller

15
推荐指数
1
解决办法
1337
查看次数

为什么我的应用程序在使用[NSAttributedString initWithData]时进行后台处理时崩溃

我有一个管理UICollectionView的viewController.我有一个从cellForItemAtIndexPath调用的辅助方法,它为单元格中的标签提供NSAttributedString.helper方法从html字符串格式化NSAttributedString.当移动到后台时应用程序会崩溃,但前提是indexPath.item大于1.换句话说,我可以退出应用程序而不会从第一个或第二个单元格崩溃,但是在第三个,第四个,第四个,. .. 细胞.

这是我的帮助方法和堆栈跟踪.知道为什么我在退出应用程序时崩溃了吗?

#pragma mark - === Utility Methods === -

- (NSAttributedString *)stepDescriptionStringForIndexPath:(NSIndexPath *)indexPath {

    NSString *headerString;
    NSString *htmlString;
    NSString *categoryString = [NSString stringWithFormat:@"Category: %@", self.knot.category.categoryName];
    NSString *abokString = [NSString stringWithFormat:@"ABOK #: %@", self.knot.abokNumber];
    NSMutableString *activitiesString = [NSMutableString stringWithCapacity:10];
    [activitiesString appendString:@"Activities: "];

    // build a string of activities to append to the description html
    NSArray *activities = [self.knot.activities allObjects];
    if ([activities count] > 0) {
        int counter = 1;
        for (Activity *activity in activities) {
            [activitiesString appendString:activity.activityName];
            if …
Run Code Online (Sandbox Code Playgroud)

ios

14
推荐指数
1
解决办法
1758
查看次数

iOS在UITableViewCells之间显示UIPickerView

在iOS 7中,鼓励开发人员在需要输入时在表格单元格之间显示日期选择器,然后在完成后隐藏它们.我怎样才能达到这个效果?

在此输入图像描述

objective-c uipickerview ios7

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

声明包含对象的对象数组

我有一个包含其他对象的对象数组.目前我宣布他们的方式很长.是否有更多浓缩方式来执行以下操作:

function city(name,population)
{
 this.name = name;
 this.population = population;
}

function state(name)
{
 this.name= name;
 this.cities = new Array();
}

function country(name)
{
 this.name= name;
 this.states = new Array();
}

Countries = new Array();
Countries[0] = new Country("USA");
Countries[0].states[0] = new State("NH");
Countries[0].states[0].cities[0] = new city("Concord",12345);
Countries[0].states[0].cities[1] = new city("Foo", 456);
...
Countries[3].states[6].cities[35] = new city("blah", 345);
Run Code Online (Sandbox Code Playgroud)

有没有办法声明这个设置不是那么冗长,类似于xml如何布局,类似于:

data =
usa
  NH
     concord: 34253
     foo: 3423
     blah: 99523
  NC
     place: 23522
Uk
  foo
     bar: 35929
     yah: 3452
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚如何嵌套数组声明而不必经常重复变量名称.

javascript arrays

12
推荐指数
1
解决办法
4万
查看次数

iOS应用内购买计数错过匹配

我们的应用程序节目的iTunes Connect DAILY报告可以说每天52次购买 ......但根据我们的服务器日志,在交付项目的同一天处理了55次购买.

这怎么可能?

我们的服务器保留所有原始购买收据(全部55个),即使现在我们也可以成功地使用苹果服务器重新验证所有这些收据.

我们在收据中使用" original_purchase_date_pst "来识别我们相信iTunes在下载DAILY报告时使用的购买日期(我们确实尝试过与收据中的所有其他"purchase_date"字段匹配...但没有成功)

每日报告显示无退款......

我们对所有55次购买都有" transaction_id ",但没有办法将它们与每日报告相匹配.

请帮忙,

更新: 联系Apple并获得模板响应(如预期的那样)......

"Apple销售和趋势报告按预期工作.我们无法解释我们的报告与任何外部报告系统之间的任何差异.如果您对此信息有其他疑问,请告诉我们.您可以在周一至周五与我联系,从上午7:00到下午5:00(太平洋标准时间)1(877)-206-2092."

我已经向他们发送了详细信息......但他们甚至都不会看到它!

更新: 好的,考虑它是否是退款(或@Ricky建议的REVERSAL),我们如何检查哪个交易被退还?我们确实拥有所有的transaction_id,但Apple报告没有显示任何内容.

itunesconnect in-app-purchase ios

10
推荐指数
1
解决办法
1012
查看次数