Questions tagged «objective-c»

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

7
结合使用C ++和Cocoa而非Objective-C?
我想编写使用C ++和Cocoa框架的应用程序,因为Apple并未使Carbon具备64位功能。C ++在Linux和Windows上的实现似乎很原始,但在Mac OS X上似乎需要附加的Apple特定代码段(如Obj-C包装程序)。尽管我可能错了,但苹果似乎也在强迫开发人员使用Objective-C而不是C ++进行编写。 我正在尝试寻找一种在Mac上编写代码的方法,该方法很容易保持跨平台。必须为Linux / Windows用C ++编写代码,然后再用Objective-C重写大部分代码,效率非常低下。 有没有一种方法可以用C ++编写将来会受Xcode支持的代码?另外,如果有可能,我该如何在Xcode中混合使用C ++和Objective-C?谢谢。

14
了解可可和Objective-C的参考计数
我刚刚开始研究Objective-C和Cocoa,以期使用iPhone SDK。我对C malloc和free概念很满意,但是Cocoa的引用计数方案使我感到困惑。有人告诉我它非常优雅,但是我还没有结束。 怎么办release,retain和autorelease工作有什么关于他们使用的约定? (或者失败了,您读了什么书,对您有所帮助?)

5
在Object-C中将NSNumber转换为int
我使用[NSNumber numberWithInt:42]或@(42)将int转换为NSNumber,然后再将其添加到NSDictionary中: int intValue = 42; NSNumber *numberValue = [NSNumber numberWithInt:intValue]; NSDictionary *dict = @{ @"integer" : numberValue }; 当我从NSDictionary检索值时,如何将其从NSNumber转换回int? NSNumber *number = dict[@"integer"]; int *intNumber = // ...? 它抛出一个异常,表示我以这种方式进行铸造时需要铸造: int number = (int)dict[@"integer"];

11
将UIButton字体大小调整为宽度
我有以下代码: UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.frame = CGRectMake(0.0, 0.0, 25, 25); [[button layer] setCornerRadius:5.0f]; [[button layer] setMasksToBounds:YES]; [[button layer] setBackgroundColor:[[UIColor redColor] CGColor]]; [button.titleLabel setFrame:CGRectMake(0,0, 25, 25)]; [button setTitle:[NSString stringWithFormat:@"%@", [[topics objectAtIndex:indexPath.row] unread]] forState:UIControlStateNormal]; 问题是当文本中的字符串不长时,它可以正常显示(1-2位)。但是,当它很长时(3 ++位),我只能看到一个红色按钮,里面没有文本。我该如何调整? 我不认为: [button.titleLabel setAdjustsFontSizeToFitWidth:YES]; 做这份工作,对不对?
122 ios  objective-c 

14
使用CALayers的圆形UIView-仅在某些角落-如何?
在我的应用程序中-有四个按钮,名称如下: 左上方 左下方 右上 底部-右 在按钮上方有一个图像视图(或UIView)。 现在,假设用户点击-顶部-左按钮。上方的图片/视图应在该特定角处四舍五入。 我在将圆角应用于UIView时遇到了一些困难。 现在,我正在使用以下代码将圆角应用于每个视图: // imgVUserImg is a image view on IB. imgVUserImg.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"any Url Here"]; CALayer *l = [imgVUserImg layer]; [l setMasksToBounds:YES]; [l setCornerRadius:5.0]; [l setBorderWidth:2.0]; [l setBorderColor:[[UIColor darkGrayColor] CGColor]]; 上面的代码将圆度应用于提供的View的每个角。相反,我只是想将圆度应用于选定的角,例如-顶部/顶部+左侧/底部+右侧等。 可能吗?怎么样?

9
将NSArray过滤到Objective-C中的新NSArray中
我有一个NSArray,我想NSArray使用满足特定条件的原始数组中的对象创建一个新对象。条件由返回的函数决定BOOL。 我可以创建一个NSMutableArray,遍历源数组,并复制过滤器函数接受的对象,然后创建它的不可变版本。 有没有更好的办法?

3
如何使一个类符合Swift中的协议?
在Objective-C中: @interface CustomDataSource : NSObject <UITableViewDataSource> @end 在Swift中: class CustomDataSource : UITableViewDataSource { } 但是,将出现一条错误消息: 类型“ CellDatasDataSource”不符合协议“ NSObjectProtocol” 类型“ CellDatasDataSource”不符合协议“ UITableViewDataSource” 正确的方法应该是什么?
121 objective-c  swift 

10
像iPhone上的Facebook应用程序一样的SplitView
我想创建一个使用类似于链接中所示导航场景的iPhone应用程序 请注意,我不希望它仅适用于iPad,我希望它完全适用于iPhone,如图所示,当您单击表格视图项时,它将隐藏该表格视图并使该视图全屏显示。我想要有关如何执行此操作的想法,因为我自己无法解决。 谢谢



22
检测到约束不明确地提示高度为零的情况
当我运行包含表视图单元的应用程序时,更新到Xcode 6.1 beta 2后,调试助手会说: Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead. 以前,当我在该项目上使用Xcode 5时,会遇到一些错误,但是自升级以来,这些错误已经消失了。我现在没有其他错误或警告。我已经尝试过调整所有tableview单元格的大小,也尝试过使用标准高度,但是仍然收到相同的警告: Warning once only: Detected a case where constraints ambiguously suggest a height of zero …

7
这个gdb输出是什么意思?
我有一个可以播放声音的按钮,它在模拟器上似乎工作得很好,但是我收到以下消息: 加载/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:dlopen(/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIns.bundle/Content时出错MacOS / AudioIPCPlugIn,262):找不到符号:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期位于:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security中 2011-11-01 02:13:02.605万圣节FX [33484:10703]加载/System/Library/Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn:dlopen(/ System / Library /Extensions/AudioIPCDriver.kext/Contents/Resources/AudioIPCPlugIn.bundle/Contents/MacOS/AudioIPCPlugIn,262):找不到符号:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期位于:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security中 2011-11-01 02:13:02.657 Halloween FX [33484:10703]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library /Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期位于:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security中 2011-11-01 02:13:02.671万圣节FX [33484:10703]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library /Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期位于:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation 在/System/Library/Frameworks/Security.framework/Versions/A/Security中 2011-11-01 02:13:02.706 Halloween FX [33484:10703]加载/System/Library/Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn:dlopen(/ System / Library /Extensions/AppleHDA.kext/Contents/PlugIns/AppleHDAHALPlugIn.bundle/Contents/MacOS/AppleHDAHALPlugIn,262):找不到符号:___CFObjCIsCollectable 引用自:/System/Library/Frameworks/Security.framework/Versions/A/Security 预期位于:/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation …


8
#import使用尖括号<>和引号“”
我想知道是什么决定了是否允许使用&lt;Header.h&gt;或"Header.h"何时在Objective-C中导入文件。到目前为止,我的观察是,您""对实现源所在的项目中的文件使用引号,并&lt;&gt;在引用库或框架时使用尖括号。 但是,这是如何工作的呢?我要做什么才能使自己的班级使用方括号?目前,Xcode不允许我为自己的标头执行此操作。 另外,通过查看一些框架的标头,我发现这些标头之间使用相互引用&lt;frameworkname/file.h&gt;。如何做那工作的?它看起来很像Java中的软件包,但据我所知,Objective-C中没有软件包。

15
UIRefreshControl-当UITableViewController位于UINavigationController内部时,beginRefreshing不起作用
我已经在UITableViewController(位于UINavigationController内部)中设置了UIRefreshControl,并且它按预期工作(即,下拉触发正确的事件)。但是,如果我以编程beginRefreshing方式在刷新控件上调用实例方法,例如: [self.refreshControl beginRefreshing]; 没发生什么事。它应该向下动画并显示微调框。endRefreshing在刷新后调用该方法时,该方法可以正常工作。 我用这种行为鞭打了一个基本的原型项目,当我的UITableViewController直接添加到应用程序委托的根视图控制器时,它可以正常工作,例如: self.viewController = tableViewController; self.window.rootViewController = self.viewController; 但是,如果我tableViewController先将添加到UINavigationController,然后将导航控制器添加为rootViewController,则该beginRefreshing方法将不再起作用。例如 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableViewController]; self.viewController = navController; self.window.rootViewController = self.viewController; 我的感觉是,这与导航控制器中的嵌套视图层次结构与刷新控件的效果不佳有关-有任何建议吗? 谢谢

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.