Questions tagged «objective-c»

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



16
iOS 7-无法实例化默认视图控制器
我在一个新创建的应用程序中使用Xcode 5,当我刚创建它时,我点击运行按钮,然后建立了项目,但它未在iOS Simulator中显示,并且收到以下消息: Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set? 我已经在Google上进行了搜索,每个人都指出发生这种情况是因为XCode尚不知道哪个视图控制器是最初的视图控制器。但是奇怪的是,我将应用程序创建为基于页面的应用程序(也尝试过单视图和选项卡式应用程序选项),而XCode已经为其定义了一个Storyboard。 另外,当我转到项目的主界面选项时,将设置情节提要(由Xcode本身命名为“ Main”),并在情节提要中将我的视图控制器设置为“初始视图控制器”。 怎么了?



7
URLWithString:返回nil
这可能很容易,但是我似乎不知道为什么URLWithString:在这里返回nil。 //localisationName is a arbitrary string here NSString* webName = [localisationName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSString* stringURL = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@,Montréal,Communauté-Urbaine-de-Montréal,Québec,Canadae&output=csv&oe=utf8&sensor=false&key=", webName]; NSURL* url = [NSURL URLWithString:stringURL];


8
在Swift中使用谓词
我正在为我的第一个应用程序浏览本教程(学习Swift):http : //www.appcoda.com/search-bar-tutorial-ios7/ 我被困在这部分(Objective-C代码): - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText]; searchResults = [recipes filteredArrayUsingPredicate:resultPredicate]; } 谁能建议如何在Swift中为NSPredicate创建等效项?

4
如何在运行时使用Objective-C动态创建选择器?
我知道如何SEL在编译时使用创建一个,@selector(MyMethodName:)但是我想做的是从一个动态创建选择器NSString。这有可能吗? 我可以做什么: SEL selector = @selector(doWork:); [myobj respondsToSelector:selector]; 我想做什么:(伪代码,这显然行不通) SEL selector = selectorFromString(@"doWork"); [myobj respondsToSelector:selector]; 我一直在搜索Apple API文档,但是还没有找到一种不依赖于编译时@selector(myTarget:)语法的方法。

7
Objective-C中的只读属性?
我在接口中声明了一个readonly属性,例如: @property (readonly, nonatomic, copy) NSString* eventDomain; 也许我误解了属性,但是我认为当您将其声明为时readonly,您可以在实现(.m)文件中使用生成的setter ,但是外部实体无法更改该值。这样的问题说那应该发生。这就是我的行为。但是,当尝试使用标准的setter或点语法eventDomain在我的init方法内部进行设置时,它给我一个unrecognized selector sent to instance.错误。我当然在@synthesize找房子。尝试像这样使用它: // inside one of my init methods [self setEventDomain:@"someString"]; // unrecognized selector sent to instance error 那么我会误会readonly关于财产的声明吗?还是发生了其他事情?


8
iPhone上的JSON和核心数据
我有一个核心数据对象图(由通过多对多关系链接的两个实体组成)。 作为一个相对缺乏经验的iPhone开发人员,我很好奇,是否有人可以推荐一种方法以及适合iPhone的JSON实现,这将使我能够: 将核心数据记录转换为JSON字符串(同时保持实体之间的关系);和 将JSON字符串转换回核心数据对象(再次保留实体之间的关系)。 在这一点上,我没有搜索到教程/代码示例,因此将不胜感激。



27
UITextfield iOS7上的leftView / rightView填充
iOS7上的UITextField的leftView和rightView视图实际上靠近文本框边框。 如何在这些项目中添加一些(水平)填充? 我尝试修改框架,但是没有用 uint padding = 10;//padding for iOS7 UIImageView * iconImageView = [[UIImageView alloc] initWithImage:iconImage]; iconImageView.frame = CGRectMake(0 + padding, 0, 16, 16); textField.leftView = iconImageView; 请注意,我对在文本字段的文本中添加填充不感兴趣,例如使用UITextBorderStyleNone设置UITextField的填充

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.