Questions tagged «objective-c»

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

1
使用isgl3D无法正确进行3D对象(.pod)中的纹理映射
我使用了3D iphone(.pod)模型,它在PVRShammon中可以正确显示。 但是,当我将3D模型导入isgl3D时,它在带纹理的图像中无法正确显示,该图像仅覆盖了对象的某些区域,并带有一些线和三角形。 _cameraController = [[Isgl3dDemoCameraController alloc] initWithCamera:self.camera andView:self]; _cameraController.orbit = 10; _cameraController.theta = 20; _cameraController.phi = 0; _cameraController.doubleTapEnabled = NO; Isgl3dPODImporter * podImporter = [Isgl3dPODImporter podImporterWithFile:@"iPhone5Spod.pod"]; [podImporter printPODInfo]; [podImporter buildSceneObjects]; Isgl3dTextureMaterial *material2 = [[[Isgl3dTextureMaterial alloc] initWithTextureFile:@"DiffuseBody2.jpg" shininess:0.0 precision:Isgl3dTexturePrecisionHigh repeatX:YES repeatY:YES] autorelease]; mesh2 = [podImporter meshAtIndex:4]; node2 = [self.scene createNodeWithMesh: …



16
如何从自己的本机应用程序中启动Google Maps iPhone应用程序?
在苹果开发者文档(链接现在是死的)解释说,如果你把在网页中的链接,然后单击它,而在iPhone上,也作为标准配置提供与iPhone将推出谷歌地图应用程序中使用移动Safari浏览器。 如何在我自己的本机iPhone应用程序(即不是通过Mobile Safari的网页)中使用特定地址启动相同的Google Maps应用程序,就像在“通讯录”中轻按地址即可启动地图一样? 注意:这仅适用于设备本身。不在模拟器中。

5
是否有一种简单的方法可以向后遍历NSArray?
我有一个NSArray并且必须在特例中向后迭代,以便我首先查看最后一个元素。这是出于性能方面的考虑:如果最后一个没有意义,则可以忽略之前的所有内容。所以我想打破循环。但是,如果我从0迭代到n,那将行不通。我需要从n到0。也许有一个我不知道的方法或函数,所以我不必在这里重新发明轮子。

8
如何以编程方式调用View Controller?
我看了所有可以在此教程上找到的教程,但仍然没有答案。我需要从代码中调用另一个视图。我正在使用UIStoryboards。我通过从拖动控件多次更改了视图UIButtons,但是现在它必须来自代码。如果这是用户第一次打开该应用程序,我试图从主菜单调用信息页面。但是,我似乎找不到从代码中更改视图的方法。我所有的视图都由相同的文件(ViewController2)控制。在identifier我的主菜单是ViewControllerMain,而identifier该信息页面的是ViewControllerInfo。首先,我尝试了这个: [ViewControllerMain presentViewController: ViewControllerInfo animated:YES completion: NULL]; 然后,我尝试使UIViewControllers每种方法有所不同并说: [ViewController2 presentViewController: ViewController animated:YES completion: NULL]; 两者都不起作用。对于第一个,它说: 使用未声明的标识符ViewControllerMain。 在第二个中,它说: 意外的接口名称'ViewController':预期的标识符。 我能做什么?

4
'无效的更新:第0部分中的无效行数
我已经阅读了所有与此相关的文章,但仍然出现错误: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from …

7
如何正确地继承UIControl?
我不要UIButton或类似的东西。我想UIControl直接子类化并进行自己的非常特殊的控制。 但是由于某种原因,我重写的任何方法都不会被调用。目标动作材料起作用,并且目标接收适当的动作消息。但是,在我的UIControl子类中,我必须捕获触摸坐标,而这样做的唯一方法似乎是重写这些家伙: - (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { NSLog(@"begin touch track"); return YES; } - (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event { NSLog(@"continue touch track"); return YES; } 他们得到从来没有所谓的,即使UIControl与指源自初始化实例化UIView,initWithFrame:。 我可以找到的所有示例都始终使用UIButton或UISlider作为子类的基础,但我想走得更近些,UIControl因为这就是我想要的源:快速且无延迟的Touch坐标。

4
在主线程上发布NSNotification
我发现了以下代码片段,该片段允许NSNotification从任何后台线程发布到主线程上。我想知道这是否是一种安全且可以接受的做法? dispatch_async(dispatch_get_main_queue(),^{ [[NSNotificationCenter defaultCenter] postNotificationName:@"ImageRetrieved" object:nil userInfo:imageDict]; });

1
Xcode项目格式:3.1、3.2、6.3和8.0有什么区别?
当我在Xcode 9(或更早版本)中打开一个项目并检查File Inspector时,有一个名为Project Document的部分,带有一个名为Project Format的组合框。 可用的选项(在Xcode中9)有Xcode 3.1-compatible,Xcode 3.2-compatible,Xcode 6.3-compatible,和Xcode 8.0-compatible: 这些格式之间有什么区别? -更新历史(截至2019年5月20日)- 我最初在Xcode 6.4出现时问这个问题。 Xcode的6.4的名单包括Xcode 3.1-compatible,Xcode 3.2-compatible和Xcode 6.3-compatible,并默认为Xcode 3.2-compatible。 Xcode 7没有进行任何更改。 Xcode 8添加了一个Xcode 8.0-compatible项目。 Xcode 9将新项目的默认设置更改为Xcode 8.0-compatible。(2017年10月8日)添加了 Xcode 10.2Xcode 9.3-compatible,Xcode 10.0-compatible(2019年5月)

19
更改UITabBar的高度
我UITabBarController用作根视图,并且应用程序支持iOS 6及更高版本。项目类的层次结构如下。 UITabBarController - tab1 - UINavigationController - UIViewController - UIViewController . . - tab2 - UINavigationController - UIViewController - UIViewController . . . - tab3 - UIViewController - tab4 - UIViewController 我使用下面的代码来更改上面层次结构UITabBar中的一个UIViewControllers(位于里面UINavigationController)的高度。 CGRect tabbarFrame = self.tabBarController.tabBar.frame; tabbarFrame.size.height += 60; self.tabBarController.tabBar.frame = tabbarFrame; 但是它并没有改变高度。UITabBar以默认高度显示。尽管记录其值会打印更改的值,如下所示。 <UITabBar: 0xb528f60; frame = (0 431; …


12
对ARC下的对象的弱引用(__unsafe_unretained)的NSArray
我需要在NSArray中存储对对象的弱引用,以防止保留周期。我不确定要使用的语法是否正确。这是正确的方法吗? Foo* foo1 = [[Foo alloc] init]; Foo* foo2 = [[Foo alloc] init]; __unsafe_unretained Foo* weakFoo1 = foo1; __unsafe_unretained Foo* weakFoo2 = foo2; NSArray* someArray = [NSArray arrayWithObjects:weakFoo1, weakFoo2, nil]; 请注意,我需要支持iOS 4.x,__unsafe_unretained而不是__weak。 编辑(2015-02-18): 对于那些想要使用真实__weak指针(不是__unsafe_unretained)的人,请改用以下问题:在ARC下对弱引用进行归零的集合

5
Core-Data中的自定义设置方法
我需要foo在的子类中为字段(我们将其称为)编写自定义的setter方法NSManagedObject。foo是在数据模型中定义的,并且Xcode分别自动生成了.h和.m文件中的@property和@dynamic字段。 如果我这样写我的二传手: - (void)setFoo: (NSObject *)inFoo { [super setFoo: inFoo]; [self updateStuff]; } 然后在调用时收到编译器警告super。 或者,如果我这样做: - (void)setFoo: (NSObject *)inFoo { [super setValue: inFoo forKey: inFoo]; [self updateStuff]; } 然后我陷入无限循环。 那么为NSManagedObject的子类编写自定义设置器的正确方法是什么?

2
如果启用了模块,则tgmath.h不起作用
在处理arm64时,我考虑使用tgmath.h来处理CGFloat typedef float/double混乱。 这个答案对如何使用它有很好的描述,除了它对我一点都不起作用。无论如何,我的代码仍在调用math.h函数。 花了一些时间查看所有项目编译器设置后,我发现禁用“模块”功能(@import vs #import-iOS 7)可以使所有功能正常工作。更具体地说,在项目设置中的选项被称为Enable Modules(C and Objective-C)在Apple LLVM 5.1 - Language - Modules下拉列表中。 要查看此问题的快速示例,请下载使用tgmath的项目,例如MBProgressHUD,并查看启用模块项目设置时会发生什么。该tgmath.h呼叫会被替换成普通math.h电话。 我的问题是: 为什么模块会阻止tgmath正确导入? 有没有一种解决方法,可以同时使用tgmath和模块?我仍然希望能够使用它们。

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.