Questions tagged «objective-c»

仅在有关Objective-C功能或取决于语言代码的问题上使用此标记。标签[cocoa]和[cocoa-touch]应该用于询问Apple的框架或类。使用相关标签[ios],[macos],[apple-watch]和[tvos]来解决特定于这些平台的问题。


10
在iOS8中无法获取正确的键盘高度值
我正在使用此代码来确定键盘的大小: - (void)keyboardWillChange:(NSNotification *)notification { NSDictionary* keyboardInfo = [notification userInfo]; NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey]; CGRect keyboardFrameBeginRect = [keyboardFrameBegin CGRectValue]; } 我正在模拟器中运行它。 问题是因为iOS 8不会给出正确的值,如果键盘建议是向上的,或者如果我按下它们,则会得到不同的(不正确的)值。 如何获得包括键盘建议在内的键盘的确切尺寸?




7
了解NSString比较
以下两个比较的评估结果均为true: 1) @"foo" == @"foo"; 2) NSString *myString1 = @"foo"; NSString *myString2 = @"foo"; myString1 == myString2; 但是,在某些情况下,肯定NSString无法使用相等运算符比较两个s,而是必须使用两个运算符[myString1 isEqualToString:myString2]。有人可以阐明这一点吗?

5
Xcode 4“清理”与“清理构建文件夹”
您在每个应用程序的开发中都遇到了某个特定的问题,即您在模拟器中看到的内容与您认为应该发生的情况不符。这些通常是人为错误-或至少在我的大多数情况下是;-)-但有时Xcode只是“迷路了”,似乎如此。我了解到Clean(Shift + Cmd + K)和Clean Build Folder…(Option + Shift + Command + K)菜单选项可以显示您的错误或Xcode之间的差异。 我的问题是: 该Clean命令执行或不执行什么操作,从而Clean Build Folder…导致存在的原因?什么时候应该选一个,为什么不总是清理整个文件夹?


5
将NSString转换为NSDictionary / JSON
我将以下数据另存为NSString: { Key = ID; Value = { Content = 268; Type = Text; }; }, { Key = ContractTemplateId; Value = { Content = 65; Type = Text; }; }, 我想将此数据转换为NSDictionary包含键值对的。 我首先尝试将转换NSString为JSON对象,如下所示: NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; 但是当我尝试: NSString * test = …


10
UIGestureRecognizer阻止子视图以处理触摸事件
我正在尝试找出正确的方法。我试图描述这种情况: 我要添加一个UITableView作为的子视图UIView。在UIView一个分接开关和响应pinchGestureRecognizer,但这样做的情况下,实现代码如下停止反应,这两个手势(它仍然反应刷卡)。 我已经将其与以下代码一起使用,但这显然不是一个不错的解决方案,并且我相信有更好的方法。这放在UIView(超级视图)中: -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { if([super hitTest:point withEvent:event] == self) { for (id gesture in self.gestureRecognizers) { [gesture setEnabled:YES]; } return self; } for (id gesture in self.gestureRecognizers) { [gesture setEnabled:NO]; } return [self.subviews lastObject]; }

10
自定义UITableViewCell选择样式?
当我单击UITableViewCell时,单击单元格时,背景部分(背景图像未覆盖的区域)变为蓝色。另外,UILabel单击该单元格上的所有s都会变成白色,这正是我想要的。 但是,我不希望单击的是蓝色背景,但是如果单击selectionstylenone,则会丢失UILabel单元格中s的突出显示颜色。 那么,有什么方法可以在单击单元格时摆脱蓝色背景,而保持UILabels的突出显示颜色吗?

17
解析NSURL查询属性
我有一个类似的网址 myApp://action/1?parameter=2&secondparameter=3 通过属性查询,我得到了我的一部分 URL parameter=2&secondparameter=3 有什么简单的方法可以将其放在aNSDictionary或an中Array吗? 多谢


6
不推荐使用sizeWithFont方法。boundingRectWithSize返回意外值
在iOS7中,sizeWithFont它已弃用,因此我正在使用boundingRectWithSize(它返回CGRect值)。我的代码: UIFont *fontText = [UIFont fontWithName:[AppHandlers zHandler].fontName size:16]; // you can use your font. CGSize maximumLabelSize = CGSizeMake(310, 9999); CGRect textRect = [myString boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:fontText} context:nil]; expectedLabelSize = CGSizeMake(textRect.size.width, textRect.size.height); 在中textRect,我得到的尺寸大于maximumLabelSize使用的尺寸,与使用时的尺寸不同sizeWithFont。我该如何解决这个问题?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.