小编Dam*_*amo的帖子

将iOS目标c对象转换为JSON字符串

我有一个客观的C类,

@interface message : NSObject {
 NSString *from;
 NSString *date;
 NSString *msg;
}
Run Code Online (Sandbox Code Playgroud)

我有一个NSMutableArray这个消息类的实例.我想使用iOS 5 SDK中的新JSONSerialization API将NSMutableArray中的所有实例序列化为JSON文件.我怎样才能做到这一点 ?

是通过迭代NSArray中每个元素的实例来创建每个键的NSDictionary吗?有人可以帮助解决这个问题的代码吗?我无法在Google中取得好成绩,因为"JSON"会将结果偏向服务器端调用和数据传输而不是序列化.非常感谢.

编辑:

NSError *writeError = nil; 
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:notifications options:NSJSONWritingPrettyPrinted error:&writeError];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
NSLog(@"JSON Output: %@", jsonString);
Run Code Online (Sandbox Code Playgroud)

serialization json nsarray ios

25
推荐指数
2
解决办法
6万
查看次数

调试UIKit崩溃[UINavigationController initWithRootViewController]

Xcode 7.0.1

更新:

我尝试的最新事情就是打破UINavigationController的创建:

  self.viewController = [[ProjectsViewController alloc] initWithNibName:@"ProjectsViewController_iPhone" bundle:nil];
  self.navigationController = [[UINavigationController alloc] init];
  [self.navigationController setViewControllers:@[self.viewController]];
  self.window.rootViewController = self.navigationController;
  [self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)

这样做现在崩溃了

[self.window makeKeyAndVisible];
Run Code Online (Sandbox Code Playgroud)

但痕迹完全一样.

我也通过更改使用香草ViewController尝试了这个

[self.navigationController setViewControllers:@[[[UIViewController alloc] init]]];
Run Code Online (Sandbox Code Playgroud)

结果相同......

原帖:

我遇到了一个我很难理解的崩溃 - 这是lldb跟踪:请注意索引2147483648

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 2147483648 beyond bounds [0 .. 2]'
*** First throw call stack:
(
0   CoreFoundation                      0x035eaa94 __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x03084e02 objc_exception_throw + 50
2   CoreFoundation                      0x034f92ed -[__NSArrayM removeObjectAtIndex:] + …
Run Code Online (Sandbox Code Playgroud)

debugging objective-c uikit ios

21
推荐指数
1
解决办法
1335
查看次数

FBSDKShareDialog在发布时取消

我在代码中创建了一个FBSDKShareDialog

- (void)shareWithFacebookDialog;
{  
  FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
  content.contentURL = [NSURL URLWithString:@"Path Redacted"];
  content.contentTitle = @"Title Redacted";
  content.contentDescription = @"Description Redacted";

  FBSDKShareDialog* dialog = [[FBSDKShareDialog alloc] init];
  [dialog setMode:FBSDKShareDialogModeNative];
  [dialog setShareContent:content];
  [dialog setDelegate:self];
  [dialog setFromViewController:self];
  [dialog show];
}
Run Code Online (Sandbox Code Playgroud)

对话框启动并且所有信息都是正确的

在此输入图像描述

但是只要点击Post,对话框就会关闭,并且会调用取消委托.

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;
Run Code Online (Sandbox Code Playgroud)

有没有人见过这个?找到克服它的方法?

facebook objective-c ios

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

当我尝试构建时,添加Reachability类失败

我添加了SystemConfiguration框架.我正在部署3.2及更高版本的目标.我忘了添加一些东西吗?

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_Reachability", referenced from:
      objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

iphone linker-errors ios

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

沿弧形动画UIView

我希望沿着弧形设置动画,如图1所示,从位置1到位置2.

在此输入图像描述

实际发生的是视图动画描述了一个完整的圆而不是弧.我的问题是:

  1. 我应该使用CGPathAddArc还是CGPathAddArcToPoint
  2. 我是否需要使用CGPathMoveToPoint来描述视图的初始位置?

当我逐步执行代码时,CGPoints值与我期望的一样,角度也是如此.

我使用以下函数在圆上获取CGPoints

CGPoint pointOnCircle(CGPoint centre, float radius, float angle)
{
    float x = centre.x + radius * cosf(angle);
    float y = centre.y + radius * sinf(angle);

    return CGPointMake(x, y);
}
Run Code Online (Sandbox Code Playgroud)

我使用以下代码及其变体,但到目前为止我还没有设法破解它.

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = duration;
pathAnimation.repeatCount = 1;

CGPoint viewCenter = dynamicView.objectCenter;
CGMutablePathRef arcPath = CGPathCreateMutable();
//  CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);

//work out the half way point …
Run Code Online (Sandbox Code Playgroud)

core-graphics ios

11
推荐指数
1
解决办法
3688
查看次数

确保在NSDateFormat stringFromDate中不出现AM/PM(句点)

Unicode日期格式模式指南(此处)指出在格式中附加'a'将获得句点(例如,AM或PM),例如,

[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss a"];
Run Code Online (Sandbox Code Playgroud)

但是,我希望确保没有出现期间信息,但我找不到格式字符串来执行此操作.我使用的格式字符串如下:

[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我使用stringFromDate时,我得到以下内容:

2013-01-09T11:11:00 AM

我不希望简单地从结果字符串中删除AM或PM,因为句点语法在不同的日历等中可能不同,我只想停止出现的句点信息.

---- 8 <------

请考虑以下代码

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSString *stringDate = [formatter stringFromDate:[NSDate date]];

self.labelOutput.text = stringDate;

[formatter release];
Run Code Online (Sandbox Code Playgroud)

此代码将生成我想要的格式的字符串 - 但是我不能将其用于内存管理原因.我正在处理的应用程序受到NSDateFormatter内存泄漏的困扰.因此,我们使用单例类为应用程序提供一组永远不会释放的固定数量的NSDateFormatters,因此我们最大限度地减少了泄漏的内存量.不幸的是,即使我应用日期格式字符串,这些静态NSDateFormatters也会附加AM/PM:

NSDateFormatter *formatter = [MyDateFormatter dateFormat:kFormatDateMediumStyleTimeShortStyle];

[formatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
Run Code Online (Sandbox Code Playgroud)

objective-c ios

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

推送弹出导航堆栈后,UIBarButtonItem字体粗细更改

我有一个UIBarButtonItem,"完成" - 在ViewController A的故事板IB中创建.

ViewController A是导航堆栈的根视图控制器.

如果我将视图控制器B推入导航堆栈然后再次弹出.完成按钮的字体粗细更改.

开始场景 -  A. B推到堆栈上 B从堆栈中弹出

完成按钮的字体颜色应用于A.viewWillAppear(..),看起来非常像

doneButton.tintColor = [CMPThemes navigationBarItemColour]; // it's a blue
Run Code Online (Sandbox Code Playgroud)
  • 我从应用程序中删除了所有外观代理代码(因为应用程序中出现了多种导航栏/按钮/标题样式)所以我不是在寻找只能通过外观代理完成的修复程序. .

  • 我已经在调试视图层次结构中检查了Done按钮在转换之前和之后是相同的实例

  • 我试图在弹出后重新应用色调颜色

  • 我不会在过程中的任何位置应用字体粗细

  • 另外,在我看来,字体和字体大小在此过程中似乎没有变化.

在ViewController中

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    ...
    self.navigationController?.pushViewController(vcB, animated: true)
    ...
Run Code Online (Sandbox Code Playgroud)

在ViewController B中

viewDidLoad() {
    ...
    let backButton = UIBarButtonItem(image: UIImage(named: "arrowLeft"), style: .plain, target: self, action: #selector(goBack))
    backButton.tintColor = CMPThemes.popoverNavigationBarItemColour()
    self.navigationItem.leftBarButtonItem  = backButton
}
Run Code Online (Sandbox Code Playgroud)

故事板看起来像:(我已将A和B添加到图像中以保持清晰度).

在此输入图像描述

如果有人认识到这个问题并且可以指出我正确的方向进行修复,这将是非常好的!

uinavigationcontroller uibarbuttonitem ios

6
推荐指数
1
解决办法
231
查看次数

在UIViews图层动画化后,UIView上的UIPanGestureRecognizer表现得很奇怪

我有一系列UIViews,我沿着弧线动画.每个视图都有一个UIPanGestureRecognizer,它在任何动画发生之前按预期工作.

但是,在为视图设置动画后(使用下面的方法为视图的图层设置动画),手势无法按预期工作; 事实上,它似乎在原始屏幕位置工作.

我尝试了各种各样的事情,包括将视图框架和/或边界与动画图层上的视图框架和/或边界相​​匹配,甚至删除现有的手势并再次创建和添加它们(下面未显示).

如果有人知道发生了什么,或者可以让我在解决问题的道路上,我将不胜感激.

编辑: iMartin的改变建议

pathAnimation.removedOnCompletion = NO;
Run Code Online (Sandbox Code Playgroud)

pathAnimation.removedOnCompletion = YES;
Run Code Online (Sandbox Code Playgroud)

view.layer.position = ... //
Run Code Online (Sandbox Code Playgroud)

让我开始解决这个问题.

原始代码:

- (void)animateUIViewAlongArc:(UIView*)view clockwise:(BOOL)clockwise duration:(float)duration
{
    [UIView animateWithDuration:duration animations:^{

    CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimationanimationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = NO;
    pathAnimation.repeatCount = 1;

    CGPoint viewCenter = view.objectCenter;
    CGMutablePathRef arcPath = CGPathCreateMutable();
    CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);

    float angleOfRotation = self.angleIncrement;
    if (clockwise == NO)
    {
        angleOfRotation *= -1.0f;
    }

    float fullwayAngle = view.angle + angleOfRotation;
    CGPoint fullwayPoint = pointOnCircle(self.center, …
Run Code Online (Sandbox Code Playgroud)

objective-c uiview uigesturerecognizer caanimation ios

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

带有keyboardAccessoryView的UITextView键盘在Springboard之后变为蓝色(反转)

在iOS8设备或iOS8模拟器上:

我有一个UITextView成为第一响应者.一切都很好,直到应用程序重新启动(通过主页按键).

当应用程序再次变为活动状态时,键盘的外观会发生变异 - 请参阅图像

在此输入图像描述

键盘确实有一个keyboardAccessoryView,我已从图像中删除它以保护客户端隐私.但是,如果删除keyboardAccessoryView,则不会发生不良行为.

我迄今为止唯一的解决方案是在UIApplicationWillResignActiveNotification上的 resignFirstResponder和UIApplicationDidBecomeActiveNotification上的firstFirstResponder .

有没有其他人看过这个问题并[希望]修复它?

为了完整性,这里是应用程序进入Springboard之前键盘的屏幕截图

在此输入图像描述

keyboard uitextview ios xcode6 ios8

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

如何在Ruby on Rails中使用Base64编码?

我正在Ruby on Rails中的Base64中工作,并且有一个问题:

例如,如何对Base64进行以下编码/解码?

<a href="myroute?id=<%=@client.id%>"> MY LINK</a>
Run Code Online (Sandbox Code Playgroud)

base64 ruby-on-rails

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

如何在 Swift 中解码命名的 json 对象数组

我有一个命名的 json 对象数组,我通过 API 调用接收到它。

{
    "Images": [{
        "Width": 800,
        "Height": 590,
        "Url": "https://obfuscated.image.url/image1.jpg"
        }, {
        "Width": 800,
        "Height": 533,
        "Url": "https://obfuscated.image.url/image2.jpg"
        }, {
        "Width": 800,
        "Height": 478,
        "Url": "https://obfuscated.image.url/image3.jpg"
    }]
}
Run Code Online (Sandbox Code Playgroud)

这些对象是我定义的 Image 类型,并且具有可以解码单个 Image 对象的解码功能。图像看起来像:

struct Image : Codable {
    let width: CGFloat
    let height: CGFloat
    let url: String

    enum ImageKey: String, CodingKey {
        case width = "Width"
        case height = "Height"
        case url = "Url"
    }

    init(from decoder: Decoder) throws
    {
        let container = try decoder.container(keyedBy: ImageKey.self) …
Run Code Online (Sandbox Code Playgroud)

json swift jsondecoder

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

NSMutableDictionary将NSString值视为NSNumber

我在NSMutableDictionary中有以下值 - 请参阅图像

在此输入图像描述

我试图得到"a"因此:

let a = dictionary.objectForKey("a") as! String
Run Code Online (Sandbox Code Playgroud)

应用程序此时崩溃了

无法将'__NSCFNumber'(0x ...)类型的值转换为'NSString'(0x ...).

""内的其他数字被视为字符串,因为字符串之外的数字被转换为字符串而没有任何问题.

任何人都可以让我知道发生了什么事吗?以及如何轻松获得这些价值?

nsnumber nsstring nsmutabledictionary ios swift

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