Questions tagged «objective-c»

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

5
调整UIColor的Alpha
我将UIColor使用rgb 设置为的背景UILabel。我正在尝试调整alpha唯一。如何修改现有rgb的alpha UIColor? 编辑 基本上我UILabels有一套UIColor(使用rgb),我不知道它们是什么颜色UILabels。在某个时候,我将不得不更改labelsalpha`。如何更改标签颜色Alpha?

6
如何在基于块的API方法中使用非空和可空的Objective-C关键字
考虑以下方法 - (void)methodWithArg:(NSString *)arg1 andArg:(NSString *)arg2 completionHandler:(void (^)(NSArray *results, NSError *error))completionHandler; 使用new nonnull和nullable 注解关键字,我们可以按如下方式丰富它: - (void)methodWithArg:(nonnull NSString *)arg1 andArg:(nullable NSString *)arg2 completionHandler:(void (^)(NSArray *results, NSError *error))completionHandler; 但我们也会收到以下警告: 指针缺少可空性类型说明符(__nonnull或__nullable) 它引用第三个参数(块一)。 该文档没有提供有关如何指定块参数的可空性的示例。它说逐字记录 只要类型是简单的对象或块指针,就可以在圆括号后立即使用非下划线形式的nullable和nonnull。 我尝试将两个关键字之一放在该块上(任何位置),但没有任何运气。还尝试了下划线前缀的变体(__nonnull和__nullable)。 因此,我的问题是:如何为块参数指定可为空的语义?

16
是否可以更改UIButtons背景颜色?
这个让我难过。 是否有可能在iPhone的Cocoa中更改UIButton的背景颜色。我试过设置背景颜色,但它只会改变角落。setBackgroundColor:似乎是可用于此类事情的唯一方法。 [random setBackgroundColor:[UIColor blueColor]]; [random.titleLabel setBackgroundColor:[UIColor blueColor]];

17
使用UIViewControllerContextTransitioning,“来自View Controller”消失
我遇到一个问题,下面已经描述了。 我正在使用UIViewControllerContextTransitioning自定义过渡。 我有2个视图控制器,第一个视图控制器和第二个视图控制器。 现在,我想用动画在第一个视图控制器上添加第二个视图控制器。我已经实现了,现在第二个视图控制器是透明的,因此我们可以在第二个视图控制器下面看到第一个视图控制器。 但是我看不到第一个视图控制器,并且只能在第二个视图控制器下方看到黑屏。 -(void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext{ self.transitionContext = transitionContext; if(self.isPresenting){ [self executePresentationAnimation:transitionContext]; } else{ [self executeDismissalAnimation:transitionContext]; } } -(void)executePresentationAnimation:(id<UIViewControllerContextTransitioning>)transitionContext{ UIView* inView = [transitionContext containerView]; UIViewController* toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; CGRect offScreenFrame = inView.frame; offScreenFrame.origin.y = inView.frame.size.height; toViewController.view.frame = offScreenFrame; toViewController.view.backgroundColor = [UIColor clearColor]; fromViewController.view.backgroundColor = …


6
Swift本机基类或NSObject
我测试了一些用Swift 编写的isa,发现它仅在NSObject是超类(直接或更高级)或使用'@objc'装饰时才有效。否则,它将遵循静态和vtable-dispatch样式,例如C ++。 定义没有Cocoa / NSObject基类的Swift类是否正常?如果我担心的话,这意味着要放弃Objective-C的许多活力,例如方法拦截和运行时自省。 动态运行时行为位于属性观察器,核心数据,面向方面的编程,高阶消息传递,分析和日志记录框架等功能的核心。 使用Objective-C的方法调用样式会将大约20个机器代码操作数添加到方法调用中,因此在某些情况下(对带有小实体的方法进行许多紧密调用),C ++样式的静态和vtable分派可以更好地执行。 但是考虑到一般的95-5规则(95%的性能提升来自调整5%的代码),从强大的动态功能入手并在必要时进行强化是否有意义?

20
如何检查UILabel是否被截断?
我有一个UILabel依赖于我的应用程序是否被纵向或横向模式下运行在iPhone或iPad,可以长短不一。当文本太长而无法在一行上显示并且被截断时,我希望用户能够按它并弹出全文本。 如何检查,是否UILabel将文本截断?可能吗?现在,我只是根据自己所处的模式来检查不同的长度,但是它不能很好地工作。

16
即使图像较小,如何使UITableViewCell的ImageView固定大小
我有一堆用于单元格图像视图的图像,它们都不大于50x50。例如40x50、50x32、20x37 ..... 加载表格视图时,文本不会对齐,因为图像的宽度会有所不同。另外,我希望小图像出现在中央而不是左侧。 这是我在“ cellForRowAtIndexPath”方法中尝试的代码 cell.imageView.autoresizingMask = ( UIViewAutoresizingNone ); cell.imageView.autoresizesSubviews = NO; cell.imageView.contentMode = UIViewContentModeCenter; cell.imageView.bounds = CGRectMake(0, 0, 50, 50); cell.imageView.frame = CGRectMake(0, 0, 50, 50); cell.imageView.image = [UIImage imageWithData: imageData]; 如您所见,我已经尝试了一些方法,但是没有一个起作用。



4
是什么使钥匙串物品与众不同(在iOS中)?
我的问题涉及iOS(iPhone,iPad等)中的钥匙串。我认为(但不确定)在Mac OS X下实施钥匙串会引起同样的问题,且答案相同。 iOS提供了五种类型(类)的钥匙串项目。您必须为该键选择这五个值之一kSecClass来确定类型: kSecClassGenericPassword used to store a generic password kSecClassInternetPassword used to store an internet password kSecClassCertificate used to store a certificate kSecClassKey used to store a kryptographic key kSecClassIdentity used to store an identity (certificate + private key) 看完苹果的文档,博客和论坛条目的很长一段时间,我发现这种类型的钥匙串项目kSecClassGenericPassword从属性得到它的独特性kSecAttrAccessGroup,kSecAttrAccount和kSecAttrService。 如果请求1中的这三个属性与请求2中的相同,则无论其他任何属性如何,您都会收到相同的通用密码钥匙串项。如果此属性中的一个(或两个或所有)更改其值,那么您将获得不同的项目。 但是kSecAttrService仅适用于类型的项目kSecClassGenericPassword,因此它不能成为任何其他类型的项目的“唯一键”的一部分,并且似乎没有文档明确指出哪些属性唯一地确定了钥匙串项目。 “ GenericKeychain”的“ KeychainItemWrapper”类中的示例代码使用该属性kSecAttrGeneric使一个项目唯一,但这是一个错误。在本示例中,这两个条目仅存储为两个不同的条目,因为它们kSecAttrAccessGroup是不同的(一个设置了访问组,另一个设置了访问组)。如果您尝试使用Apple的添加不带访问组的第二个密码KeychainItemWrapper,则将失败。 所以,请回答我的问题: 这是真的,那的组合kSecAttrAccessGroup,kSecAttrAccount并且kSecAttrService是一个钥匙串项目,其kSecClass是“唯一钥匙” kSecClassGenericPassword? …


30
UICollectionView的cellForItemAtIndexPath没有被调用
只有第二次使用UICollectionView了,也许我咬的东西比我可以咀嚼的要多,但是: 我正在实现一个UICollectionView(myCollectionView),它使用已子类化的自定义UICollectionViewCell。子类化的单元格(FullReceiptCell)包含UITableView,并且是viewcontroller的大小。我试图允许FullReceiptCells之间的水平滚动。 包含myCollectionView的子类UICollectionViewController被推入导航控制器堆栈。当前,myCollectionView区域和水平滚动已启用。但是,看不到任何单元格。我已经确认 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 已运行并返回大于0的整数。我还确认myCollectionView的委托和数据源已在IB中正确设置为子类UICollectionViewController。 加载单元格的方法: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 没有被调用。 这是我在该控制器内推送UICollectionViewController和viewDidLoad方法的位置(注意:initWithBill是常规初始化程序的替代): 在先前的ViewControllers .m文件中: FullReceiptViewController *test = [[FullReceiptViewController alloc] initWithBill:currentBill]; test.title = @"Review"; [self.navigationController pushViewController:test animated:YES]; 在FullReceiptViewController.m中: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self.myCollectionView …


5
获取UITableView的选定索引
我想为选择索引UITableView。我写了以下代码: NSIndexPath *index = [NSIndexPath indexPathForRow:1 inSection:0]; [tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:YES]; 这始终适用于第一项。我想在其中选择索引indexPathForRow. 请帮忙。谢谢。

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.