调用
NSAttributedString * as = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil];
Run Code Online (Sandbox Code Playgroud)
除主线程外,导致崩溃
1 0x194b861fc <redacted>
2 0x19801d31c <redacted>
3 0x198010eb4 _os_once
4 0x19801aa2c pthread_once
5 0x195a0858c <redacted>
6 0x195a07c78 WebKitInitialize
7 0x18bb38918 <redacted>
8 0x10020cdf0 _dispatch_client_callout
9 0x10020dcfc dispatch_once_f
10 0x1977f8bd0 <redacted>
11 0x1978009ac <redacted>
12 0x19780bdb8 <redacted>
13 0x1940b259c _NSReadAttributedStringFromURLOrData
14 0x1940b0eb4 <redacted>
15 0x1001041a0 -[MPMPostTextBrickCell attributedTextWithHTMLString:]
16 0x100103d3c __39-[MPMPostTextBrickCell setupWithBrick:]_block_invoke
17 0x187fb3508 <redacted>
18 0x187f04c94 <redacted>
19 0x187ef461c <redacted>
20 0x187fb626c <redacted>
21 0x10020cdf0 …Run Code Online (Sandbox Code Playgroud) 我想在后台线程上获取大量对象,但是我无法将它们传递给主线程,就像我得到的那样
*** Terminating app due to uncaught exception 'RLMException', reason: 'Realm accessed from incorrect thread'
Run Code Online (Sandbox Code Playgroud)
获取代码
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
//Background Thread
RLMRealm * realm = [RLMRealm defaultRealm];
self.allObjectsRLMResult = [MyClass allObjectsInRealm:realm];
dispatch_async(dispatch_get_main_queue(), ^(void){
// use self.allObjects and do stuff on main thread
});
});
Run Code Online (Sandbox Code Playgroud)
如何在后台执行提取并将对象传递给主线程,因此对性能影响最小
我可以获得主键,然后在主线程上重新获取,但这将是相同的性能(可能甚至更慢)直接获取它们
刷新颜色与色调颜色不匹配,看起来不同,我试图更改tintAdjustmentMode,但结果是一样的
需要注意的是,微调器和文本颜色应为0x2C76BE
tvc.refreshControl = [UIRefreshControl new];
tvc.refreshControl.tintAdjustmentMode = UIViewTintAdjustmentModeNormal;
tvc.refreshControl.tintColor = [UIColor colorWithHex:0x2C76BE];
tvc.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to query spectrum again" attributes:@{NSForegroundColorAttributeName:[UIColor colorWithHex:0x2C76BE]}];
Run Code Online (Sandbox Code Playgroud)
我想确定响应NSURLSessionDataTask来自缓存还是服务器提供
我正在NSURLSessionDataTask从中创建我的
request.cachePolicy = NSURLRequestUseProtocolCachePolicy;
Run Code Online (Sandbox Code Playgroud) 在NCE(通知内容扩展)中,我使用 a WKWebView,它加载本地和远程内容
但是,当手机锁定时,该方法
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
Run Code Online (Sandbox Code Playgroud)
永远不会被叫,而且
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)
Run Code Online (Sandbox Code Playgroud)
不会因任何错误而被调用
网络视图在加载时卡住了...但是当手机解锁时一切都按预期工作
这是一个错误,还是故意的?如何避免这种情况或检测此问题
电话锁定时激活 NCE 期间的控制台输出
2021-10-01 12:12:25.737559+0200 Minuta-NCE[4223:493144] [Process] 0x1022ce100 - [PID=4253] WebProcessProxy::didClose: (web process 4253 crash)
2021-10-01 12:12:25.737619+0200 Minuta-NCE[4223:493144] [Process] 0x1022ce100 - [PID=4253] WebProcessProxy::processDidTerminateOrFailedToLaunch: reason=3
2021-10-01 12:12:25.737726+0200 Minuta-NCE[4223:493144] [Process] 0x101824c18 - [pageProxyID=69, webPageID=70, PID=4253] WebPageProxy::processDidTerminate: (pid 4253), reason 3
2021-10-01 12:12:25.739596+0200 Minuta-NCE[4223:493144] [Loading] …Run Code Online (Sandbox Code Playgroud) 当观察对象到达时,如何取消注册观察者dealloced?
当观察到的对象被解除分配时,cocoa绑定如何处理这种情况?
通过使用手动KVO,我必须删除dealloc对象之前的观察(removeObserver)... Cocoa绑定如何处理这个(停止观察被观察对象的dealloc)?
我正在使用带水平滚动的UIPageViewController ...只要用户滚动,UIPageControl正常工作,当以编程方式跳转到下一页或上一页时会出现问题
[self.pageViewController setViewControllers:@[[self viewControllerWithIndex:index]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
比UIPageControl的索引不对(我会自己提供索引,但无法访问UIPageViewController的UIPageControl)
- (NSInteger)presentationCountForPageViewController:(UIPageViewController *)pageViewController {
return IntroScreensCount;
}
- (NSInteger)presentationIndexForPageViewController:(UIPageViewController *)pageViewController {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当以编程方式更改UIPageViewController页面时,如何正确获取UIPageControl的当前点索引?
我想滚动到集合视图的页脚或标题视图,但是,标准方法scrollToItemAtIndexPath只滚动到单元格
- (void)scrollToBottom {
NSInteger section = [self numberOfSectionsInCollectionView:self.collectionView] - 1;
NSInteger item = [self collectionView:self.collectionView numberOfItemsInSection:section] - 1;
if ((section > 0) && (item > 0)) {
NSIndexPath * lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[self.collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
如何滚动到任何页脚,标题视图,类似于滚动到单元格?
我想实现与[[NSFontManager sharedFontManager] addFontTrait:(nullable id)sender]仅使用我的代码相同的事情
医生说
This action method causes the receiver to send its action
message up the responder chain.
By default, the action message is changeFont:.
When a responder replies by providing a font to convert in
a convertFont: message, the receiver converts the font by
adding the trait specified by sender. This trait is determined
by sending a tag message to sender and interpreting it as a font
trait mask for a convertFont:toHaveTrait: message.
Run Code Online (Sandbox Code Playgroud)
所以我试过
NSFontManager …Run Code Online (Sandbox Code Playgroud) 我正在尝试从字符串中过滤出非字母字符,但遇到了CharacterSet使用Unicode.Scalar和字符串组成的问题Character.
Xcode 给出了错误:
无法将“String.Element”(又名“Character”)类型的值转换为指定类型“Unicode.Scalar”?
let name = "name"
let allowedCharacters = CharacterSet.alphanumerics
let filteredName = name.filter { (c) -> Bool in
if let s: Unicode.Scalar = c { // cannot convert
return !allowedCharacters.contains(s)
}
return true
}
Run Code Online (Sandbox Code Playgroud) ios ×6
cocoa-touch ×5
cocoa ×3
objective-c ×3
swift ×2
caching ×1
character ×1
dealloc ×1
ios9 ×1
notification-content-extension ×1
nstextfield ×1
nstextview ×1
nsurlsession ×1
realm ×1
string ×1
uitableview ×1
wkwebview ×1