我有UITableView基本样式单元格的静态,默认44高度.每个单元格中都有一个带有Body文本样式的标签.这样我就可以免费获得动态类型行为.
它的工作原理除外:
我设法通过跟随黑客来解决这个问题
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(preferredContentSizeChanged)
name:UIContentSizeCategoryDidChangeNotification object:nil];
}
- (void)preferredContentSizeChanged
{
// adjust the layout of the cells
// for some reason text from labels are disappear
self.statusBarCell.textLabel.text = @"Status bar";
self.itemColorCell.textLabel.text = @"Color";
Run Code Online (Sandbox Code Playgroud)
但我有另一个完全相同UITableView,这是行不通的.我试过细胞和标签的出口.我试过reloadData和setNeedsLayout方法.
这是照片.标签为黄色,内容视图为蓝色:

我的iOS应用程序播放声音AVPlayer.要做到这一点,我必须在类的顶部键入以下内容:
import AVFoundation
Run Code Online (Sandbox Code Playgroud)
我来自Objective-C背景,所以我去了Xcode项目的General选项卡,AVFoundation并通过单击Linked框架和库下的加号按钮添加它.黄色工具箱出现在我的项目中.我必须这样做吗?
我试图将它从项目中移除 - 无论是从侧边栏还是在Xcode首选项中,我的应用程序仍然有效并且声音正在播放.那么import为你处理一切吗?
我有一个简单的ksh脚本
carthage update --platform iOS作为Build pre-action运行,它在更新到Xcode 10后开始失败.在Terminal中运行命令会Carthage成功生成文件夹.
要重现此问题,请退出Xcode并删除DerivedData和Carthage文件夹.然后打开Xcode 10并尝试构建.
我得到的错误:
<unknown>:0: error: unable to load standard library for target 'arm64-apple-ios8.0-simulator'
** ARCHIVE FAILED **
The following build commands failed:
CompileSwift normal armv7
CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
CompileSwift normal arm64
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(4 failures)
Build Failed
Run Code Online (Sandbox Code Playgroud)
Cartfile 指向Alamofire 4.7.3carthage bootstrap,没有用env -i按照开放迦太基票的建议使用,没有用RayWenderlich 博客说,检查是否启用了应用内购买以正确阻止 UI 很重要:
Apple 要求您优雅地处理这种情况;不这样做可能会导致应用程序被拒绝。
当您禁用应用内购买时,限制SKPaymentQueue.canMakePayments()应该会返回,false但true无论如何它总是会返回。我尝试了 2 个不同的项目,包括这个来自 RayWenderlich 的项目。
我仅在 iOS 9 上对此进行了测试。
如何识别因家长限制而禁用的应用内购买?
更新。
有人要求分享我的代码。我认为没有必要,代码很明显,没有错误。我也可以在 Ray 的项目中重现这个问题。
// This function is called in from viewDidLoad()
// And after SKProduct is updated.
func addTextFromProduct(p: SKProduct) {
if let title = p.localizedTitle as String? {
self.navigationBar.topItem?.title = title
}
if let description = p.localizedDescription as String? {
if dailyLimit {
self.informationLabel.text? = "\(waitingTime)\(description)"
} else {
self.informationLabel.text? = "\(description)"
}
if SKPaymentQueue.canMakePayments() …Run Code Online (Sandbox Code Playgroud) 到目前为止,我发现的是这篇博客文章:是时候使用Swift Package Manager了,建议将SwiftLint和其他工具与集成Package.swift。
我能够将依赖关系添加到包文件中,并成功构建和测试,但是SwiftLint从未警告我有关语法违规的信息。
在Xcode项目中使用此“构建阶段”步骤之前,请执行以下操作:
if which swiftlint >/dev/null; then
swiftlint
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Run Code Online (Sandbox Code Playgroud)
文章建议采用蒙犬本身毫无用处没有PackageConfigs。这个想法是在提交期间运行SwiftLint命令。我试图添加两个项目,但无法在合理的时间内使它正常工作。在提交期间,我看到如下警告:
非法指示:4 $ komondor运行前提交
对于Swift Package Manager来说,这还处于初期,互联网上几乎没有信息。
理想情况下,我希望有任何可以使我们的团队自动化SwiftLint的解决方案,理想情况下,不需要添加22个依赖项,配置文件和动态库。
我们的应用程序已经UICollectionView及其dataSource字典定期更新.我们永远不知道下次更新何时会发生.可以在用户点击按钮后调用Collection View重载方法,也可以在网络请求成功后异步进行.鉴于上述信息,我们可能会在重新加载集合视图和同时更新其数据源时遇到竞争条件.我们甚至注册了下面的崩溃,我们认为它是因为上述竞争条件而发生的.崩溃消息:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
Run Code Online (Sandbox Code Playgroud)
导致崩溃的方法:collectionViewLayout sizeForItemAtIndexPath:.
此方法根据中的项目计数计算集合View的部分的高度sectionWithProducts.它崩溃,因为dataSource数量小于indexPath.row.引起崩溃的线路:
NSArray *sectionWithProducts = self.dataSource[indexPath.row];
在发生崩溃之前调用以下行:
[self.collectionView setCollectionViewLayout:[self flowLayout] animated:NO];
[self.collectionView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO];
[self.collectionView reloadData];
Run Code Online (Sandbox Code Playgroud)
为了防止这种情况,我们决定将唯一一行更新数据源的代码放入主线程中.
// Always run on main thread in hope to prevent NSRangeException.
// Reloading data should happen only sequential.
dispatch_async(dispatch_get_main_queue(), ^(void) {
self.dataSource = newValue;
});
Run Code Online (Sandbox Code Playgroud)
我们 …
在WWDC会话之一中,我获得了用于更新现有通知的代码段。我认为这行不通。尝试更新通知内容。
首先,我请求UNUserNotificationCenter始终有效的待处理通知。然后,我创建新请求以使用现有的唯一标识符更新通知。
有1个新变量content: String。
// Got at least one pending notification.
let triggerCopy = request!.trigger as! UNTimeIntervalNotificationTrigger
let interval = triggerCopy.timeInterval
let newTrigger = UNTimeIntervalNotificationTrigger(timeInterval: interval, repeats: true)
// Update notificaion conent.
let notificationContent = UNMutableNotificationContent()
notificationContent.title = NSString.localizedUserNotificationString(forKey: "Existing Title", arguments: nil)
notificationContent.body = content
let updateRequest = UNNotificationRequest(identifier: request!.identifier, content: notificationContent, trigger: newTrigger)
UNUserNotificationCenter.current().add(updateRequest, withCompletionHandler: { (error) in
if error != nil {
print(" Couldn't update notification \(error!.localizedDescription)")
}
})
Run Code Online (Sandbox Code Playgroud)
我无法捕获错误。问题在于通知内容主体 不会更改。
我试图.json在我的单元测试中读取文件并在 Swift 包中运行它。使用 Xcode 11 和 Swift 5.1
let path = Bundle.main.url(forResource: filename, withExtension: "json")
// Path is nil
Run Code Online (Sandbox Code Playgroud)
有人告诉我 Swift 包不再有捆绑包。那么我该如何解决这个问题呢?
我的 Swift.package 的一部分
.testTarget(
name: "ProjectTests",
dependencies: [
.target(name: "Project")
],
path: "Tests",
exclude: [
"Folder/File.swift"
]
)
Run Code Online (Sandbox Code Playgroud) 我正在尝试为我的 Apple Watch 界面使用 UIKit 颜色。您可以在 iOS 中使用UIColor诸如此类的类属性来完成此操作.systemBackground。例如:
let myColor = UIColor.systemBlue\nRun Code Online (Sandbox Code Playgroud)\n\n编译 watchOS 扩展目标时出现错误:
\n\n\n\n\n类型“UIColor”没有成员“UIColor.systemBlue”。
\n
我想知道是否有替代方法来获取此系统颜色,如果不是 \xe2\x80\x94 我需要的是获取某些 UI 元素的颜色,例如 SwiftUI 表视图行背景,它看起来与UIColor.systemGray5.
@State private var isActive = false\n\nvar body: some View {\n List {\n Section() {\n ForEach(self.dataSource) { item in\n CustomCell()\n .listRowPlatterColor(self.isActive ? Color(UIColor.systemGray5) : Color(.orange))\n }\n }\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n上面的代码无法编译,因为UIColor.systemGray5在 WatchKit 中找不到。我尝试创建一个在 iPhone 和 Watch 目标中都被起诉的类,它修复了 Xcode 自动完成功能。但当尝试将其用于 Apple Watch 目标时,该应用程序崩溃了。
我希望有一种方法,而不是找到正确的颜色并对其进行硬编码。 …
我正在使用以下Swift代码.
let sampleType : HKSampleType = HKSampleType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate)
let nowDate: NSDate = NSDate()
var calendar: NSCalendar = NSCalendar.autoupdatingCurrentCalendar()
let yearMonthDay: NSCalendarUnit = NSCalendarUnit.YearCalendarUnit | NSCalendarUnit.MonthCalendarUnit | NSCalendarUnit.DayCalendarUnit
var components: NSDateComponents = calendar.components(yearMonthDay , fromDate: nowDate)
var beginOfDay : NSDate = calendar.dateFromComponents(components)!
var predicate : NSPredicate = HKQuery.predicateForSamplesWithStartDate(beginOfDay, endDate: nowDate, options: HKQueryOptions.StrictStartDate)
let squery: HKStatisticsQuery = HKStatisticsQuery(quantityType: sampleType, quantitySamplePredicate: predicate, options: HKStatisticsOptions.None) { (qurt, resul, errval) -> Void in
dispatch_async( dispatch_get_main_queue(), { () -> Void in
var quantity : HKQuantity = result.averageQuantity; …Run Code Online (Sandbox Code Playgroud) 当我按下主页按钮时,我的应用程序最小化而不是关闭.当我再次启动它时,应用程序启动我在其上的最后一个视图控制器,而不是返回到第一个视图控制器.这是我的故事板:
- > A - > B - > C.
当在"C"中按回家并再次启动它时,应用程序保持"C"而不是"A"
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[super dealloc];
}
- (void)viewDidUnload {
[self setEmail:nil];
[super viewDidUnload];
}
Run Code Online (Sandbox Code Playgroud)