小编gkl*_*lka的帖子

什么是使用NSManagedObjectContext的objectWithID的"正确"方法:

文档说明:

...此方法始终返回一个对象.假定objectID表示的持久性存储中的数据存在 - 如果不存在,则在访问任何属性时(即,触发错误时),返回的对象将引发异常.此行为的好处是它允许您创建和使用故障,然后在以后或在单独的上下文中创建基础行.

在Apple的'Core Recipes'示例应用程序中,该方法的结果用于填充NSFetchRequest,然后使用请求的结果,并对此结果进行注释:

 // first get the object into the context
 Recipe *recipeFault = (Recipe *)[context objectWithID:objectID];

 // this only creates a fault, which may NOT resolve to an object (for example, if the ID is for
 // an objec that has been deleted already):  create a fetch request to get the object for real
 NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
 [request setEntity: [NSEntityDescription entityForName:@"Recipe" inManagedObjectContext:context]];
 NSPredicate *predicate = [NSPredicate predicateWithFormat: @"(self == %@)", recipeFault];
                    [request …
Run Code Online (Sandbox Code Playgroud)

cocoa core-data nsmanagedobjectcontext

6
推荐指数
1
解决办法
3770
查看次数

在Storyboard中设置UICollectionViewLayout类

我想使用这个优秀的UICollectionView布局:https://github.com/bryceredd/RFQuiltLayout

正如所料,它希望我将Collection View的布局类设置为它.这是不可能的,因为Xcode RFQuiltLayout在类字段中不接受(发出哔哔声,如果我选择其他内容则清除该字段).

我也尝试了一个新的空项目.

我错了什么?

(在Xcode 4.2.1/iOS 6和Xcode 5/iOS 7,OS X Mavericks中都有尝试.)

uicollectionview uicollectionviewlayout

6
推荐指数
1
解决办法
2860
查看次数

从 doxygen 风格的 Objective-C 注释链接到外部 URL 文档

我想写一些类似的东西:

/**
 Post a review. (For every place belongs only one review. If it was already written, the previous one will be overwritten.)

 @param placeId Place identifier
 @param rating Rating 0-5 for the place
 @param review The text the user entered for review
 @param callback Gets called either when the network request succeeds or when fails for some reason. The `success` parameter indicates this. If success is true, the contents of the `data` parameter of the response is given back …
Run Code Online (Sandbox Code Playgroud)

documentation xcode doxygen ios

6
推荐指数
1
解决办法
249
查看次数

UICollectionView窃取焦点

我有一个UICollectionView标题,一些单元格和一个页脚补充视图.标题包含一个UISearchBar.如果我在搜索字段中输入内容,键盘会在第一个字母后自动解除.我认为它是由my引起的-searchBar:textDidChange:,其中包含用于刷新集合视图的代码(通过-reloadData,因为这是我知道哪种方法有效的唯一方法).

我的理论是,重新加载UICollectionView导致它成为第一响应者,但这在某种程度上是行不通的.

每次键盘解散时,我的输出中都有这一行:

setting the first responder view of the collection view but we don't know its type (cell/header/footer)
Run Code Online (Sandbox Code Playgroud)

我试图覆盖UICollectionView-canBecomefirstResponder,但遗憾的是没有工作.

任何想法如何防止UICollectionView重新加载后成为第一响应者?

ios uicollectionview

5
推荐指数
1
解决办法
591
查看次数

UIRefreshControl跳转和刷新问题

我有一个UITableViewController内置的UIRefreshControl。我要修复的刷新动画有两个问题。

  1. 当我拖放表格视图时,它开始更新服务器中的数据。如果用户一直拖动它,则会发生明显的偏移跳跃。

  2. 刷新操作结束时,表视图将隐藏动画刷新控件。完成隐藏后,控件将闪烁几帧。

展示柜

该控件是从UIStoryboard设置的。我从那里设置目标并设置颜色。当动作触发时,我的代码刷新了我们服务器中的数据,服务器响应时该服务器具有回调。我从那里停止刷新控件:

dispatch_async(dispatch_get_main_queue(), ^{
   [self.refreshControl endRefreshing];
});
...
[self.tableView reloadData];
Run Code Online (Sandbox Code Playgroud)

我做错了还是UIRefreshControliOS 11中有故障?

objective-c uirefreshcontrol

5
推荐指数
1
解决办法
801
查看次数

在iOS 7中动态调整标签大小

在iOS 6中,我使用:

CGSize labelSize = [self.text sizeWithFont:self.font constrainedToSize:size lineBreakMode:self.lineBreakMode];
self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y , labelSize.width, self.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

动态调整UILabel的大小.这在iOS 7中不起作用,所以我尝试了:

NSString *text = self.text;
CGFloat width = size.width;
UIFont *font = self.font;
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text
                                                                 attributes:@{ NSFontAttributeName: font }];

CGRect rect = [attributedText boundingRectWithSize:(CGSize){width, CGFLOAT_MAX}
                              options:NSStringDrawingUsesDeviceMetrics
                              context:nil];
CGSize size = rect.size;

self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y , size.width, self.frame.size.height);
Run Code Online (Sandbox Code Playgroud)

这是在UILabel的一个类别中,但这也不起作用......任何想法我应该使用什么?

objective-c uilabel ios7

4
推荐指数
1
解决办法
2万
查看次数

iOS 16 更改了蓝牙 LE 连接间隔

我们正在开发一种设备,它通过蓝牙 LE 与我们的 iOS/watchOS 应用程序进行通信,并且必须在较长的时间段(数小时)内传输大量传感器数据。在 iOS 15.x 下一切正常,但我们发现 iOS 16 beta(和 RC)在协商过程中改变了一些内容:之前我们使用 15 毫秒的连接间隔,但 iOS 16(和 watchOS 8)最常使用协商的时间为 24 毫秒,这对于我们的带宽来说太宽了。长连接间隔会导致数据包丢失 (9-33%),并且在 3 次失败重试(3x30 秒)后,我们的硬件会断开连接。

我已经检查了所有可用的论坛和文档,但没有发现任何迹象表明某些内容发生了变化。我们可以研究任何新参数来解决这个问题吗?

编辑:将 30 毫秒更改为 24

ios core-bluetooth bluetooth-lowenergy ios16

4
推荐指数
1
解决办法
1893
查看次数