AFNetworking 2.0在代码块400中从代码400获取JSON

我正在使用AFHTTPRequestOperationManager POST请求。 现在我故意input不正确的信息来处理400错误代码。 现在,Web服务实际上返回一个JSON ,并向用户解释他们做错了什么。 我非常希望得到这个JSON在UIAlertView显示消息。 但是,以下的失败块: [operationManager POST:ServerURL parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: Status Code: %d", operation.response.statusCode); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Failed: Status Code: %d", operation.response.statusCode); }]; 不会像成功块中的那样传递响应对象。 那么有没有人知道我可以访问由Web服务返回的400错误的JSON? NSError *error只是给我Request failed: bad request (400)而不是返回的JSON。 任何帮助,将不胜感激, 麦克风

按stringdatesortingNSDictionaries的NSArray?

我一直在努力寻找一种简单的方法来sorting包含NSDictionaries的NSMutableArray。 每个NSDictionary都有一个名为“Date”的键,它包含一个date的NSString(例如:10/15/2014)。 我正在做的是按升序sorting基于这些string的数组。 我已经试过这个没有运气: NSComparisonResult dateSort(NSString *s1, NSString *s2, void *context) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd/yy"]; NSDate *d1 = [formatter dateFromString:s1]; NSDate *d2 = [formatter dateFromString:s2]; return [d1 compare:d2]; // ascending order return [d2 compare:d1]; // descending order } 我也试过这个没有运气: NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES]; stories=[stories sortedArrayUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]]; recent […]

“点按恢复”暂停文本SpriteKit

我知道SpriteKit已经处理暂停游戏,当应用程序进入不活动状态,但我想要做的是添加一个SKLabelNode“点击恢复”,当应用程序重新进入活动状态。 现在它正确地调用我的function,并暂停游戏,但文本不显示。 AppDelegate.swift func applicationWillResignActive(application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. […]

iOs小工具后台更新

根据苹果关于widgetPerformUpdateWithCompletionHandler的说法,iOs Widget也可以在小部件不可见时更新他的内容。 在我的debugging会话中,我注意到todayViewController被释放,每当通知中心视图消失,所以我的问题是: 如果我的todayViewController如果被释放,可以如何响应widgetPerfomrUpdateWithComplationHandler? 我需要每小时更新他的内容,如果它不可见,我怎么做? iOs小部件生命周期如何? 请帮助我:)谢谢

Swift – NSURL错误

尝试使用下面的NSURL类时出现错误,下面的代码基本上试图存储我从Facebook拉入imageView 。 错误如下: value of optional type 'NSURL?' not unwrapped, did you mean to use '!' or '?' 不知道为什么这是发生,帮助! import UIKit class ViewController: UIViewController { @IBOutlet weak var myImage: UIImageView! override func viewDidLoad() { super.viewDidLoad() let myProfilePictureURL = NSURL(string: "http://graph.facebook.com/bobdylan/picture") let imageData = NSData(contentsOfURL: myProfilePictureURL) self.myImage.image = UIImage(data: imageData) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() […]

如何清除caching的UITableViewCell

有没有人有关于如何清除caching的UITableViewCell ? 我想用reuseIdentifiercaching这些单元格。 不过,有时候我需要删除或修改一些表格行。 我希望行更改后调用reloadData 。 现在, dequeueReusableCellWithIdentifier总是返回之前的caching(过时)条目。 如何指示caching已过时并需要清除?

CTLineGetTypographicBounds的问题

代码是从SimpleTextInput sampe代码中提取的, 只是稍作修改。 创build框架: self.font = [UIFont systemFontOfSize:18.f]; CTFontRef ctFont = CTFontCreateWithName((CFStringRef) self.font.fontName, self.font.pointSize, NULL); self.attributes = [[NSDictionary dictionaryWithObject:(id)ctFont forKey:(NSString *)kCTFontAttributeName] retain]; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:self.text attributes:self.attributes]; _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributedString); // Create the Core Text frame using our current view rect bounds UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.bounds]; _frame = CTFramesetterCreateFrame(_framesetter, CFRangeMake(0, 0), [path […]

我的button上有一个阴影

我正在为iPad应用程序编程创build一个button。 当我看到button时,看起来有一个阴影types的东西在它下面。 这是什么,我怎么能摆脱它? 这是创build它的代码: UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.titleLabel.font = [UIFont fontWithName:@"Trebuchet MS" size:12]; [myButton setTitle:@"test" forState:UIControlStateNormal]; myButton.frame = CGRectMake(0, 0, self.leftScrollView.frame.size.width, 50); UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gear12.png"]]; [myButton addSubview:myImageView]; [self.leftScrollView addSubview:myButton]; 更新: 好吧,我注意到,只有当我的scrollview它的效果。 如果我把它添加到视图,没有阴影效果。 顶部的testingbutton,button是视图的子视图。 底部button是scrollview的子视图,它是视图的子视图(button/视图vsbutton/滚动视图/视图)。 白色部分是视图,灰色是滚动视图/视图。 更新2: 正如robmayor所指出的那样,UIButtons总是具有双重的线条效果,当背景颜色是白色的时候不会显眼。 蓝色是一个视图,灰色是子视图滚动视图。

ios – 简单的例子来获取相册列表?

我试图从这里获得设备中可用的相册列表: 到目前为止,我在我的viewDidLoad中有这个: // Get albums NSMutableArray *groups = [NSMutableArray new]; ALAssetsLibrary *library = [ALAssetsLibrary new]; ALAssetsLibraryGroupsEnumerationResultsBlock listGroupBlock = ^(ALAssetsGroup *group, BOOL *stop) { if (group) { [groups addObject:group]; } }; NSUInteger groupTypes = ALAssetsGroupAlbum; [library enumerateGroupsWithTypes:groupTypes usingBlock:listGroupBlock failureBlock:nil]; NSLog(@"%@", groups); 但是,没有添加到组数组。 我期待从NSLog看到2项。

检查tabBar是否在iOS应用程序中可见

我正在iOS应用程序有一个UITabBarController显示一个TabBar。 在某些地方,我提出了一个隐藏TabBar的modalView全屏幕。 我想检测当我的tabBar是可见的用户。 当tabBar可见或不可见时,有什么办法可以自动检查? 我试过了: 但它真的不工作,因为tabBar没有真正隐藏。 if ([[[appdelegate tabBarController] tabBar] isHidden]) { NSLog(@"tabBar IS HIDDEN"); } else { NSLog(@"tabBar IS VISIBLE"); } 我在一个BaseViewController中编写了这个代码,它是我的模态视图和我的项目的其他视图的超类。 谢谢。