我无法理解 Xcode 在这一行中遇到的问题:
iteration.template = template[iterationSubstring.endIndex...substring.startIndex]
Run Code Online (Sandbox Code Playgroud)
template是一个String和iterationSubstring和substring是Substring第template。Xcode 使用以下消息突出显示左方括号:
下标 'subscript(_:)' 要求类型 'Substring.Index' 和 'Int' 是等价的
错误消息对我来说没有任何意义。我尝试Substring通过Range<String.Index>使用[template.startIndex...template.endIndex]下标创建 a来获得 a 。这与 有Int什么关系?为什么同样的模式在其他地方有效?
重现问题的 Xcode 操场代码:
import Foundation
let template = "This is an ordinary string literal."
let firstSubstringStart = template.index(template.startIndex, offsetBy: 5)
let firstSubstringEnd = template.index(template.startIndex, offsetBy: 7)
let firstSubstring = template[firstSubstringStart...firstSubstringEnd]
let secondSubstringStart = template.index(template.startIndex, offsetBy: 10)
let secondSubstringEnd = template.index(template.startIndex, offsetBy: …Run Code Online (Sandbox Code Playgroud) 我开发了一个应用程序,它在 Swift 中使用 WKWebView 显示一个网页。我需要禁用用户选择和标注(因为网络加载了一个图表)并且我没有找到任何方法来使用 WKWebView 来做到这一点。
这是我的代码:
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {
@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://danfg95glucose.azurewebsites.net")
let request = URLRequest(url: url!)
webView.navigationDelegate = self
webView.load(request)
}
}
Run Code Online (Sandbox Code Playgroud)
我想做类似的事情,但在 Swift 中使用 WKWebView:
// Disable user selection
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitUserSelect='none';"];
// Disable callout
[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.style.webkitTouchCallout='none';"];
Run Code Online (Sandbox Code Playgroud)
是否可以?
这是显示问题的图像:
非常感谢您的回复。对不起,我的水平,我是新手,我正在学习编程。
我正在 Swift 4 中开发 macOS 桌面应用程序。
它有一个 WKWebView,可以加载一个发送通知的网页。
默认情况下不显示任何通知,也没有权限请求。
我需要一种方法来显示通知并拦截它们,以便我可以显示一个计数器。
知道如何实现这一目标吗?
Xcode 报告此警告:
‘swift_name’属性的参数必须是 Swift 函数名称字符串”
对于以下功能。我不知道我写错了什么。
+ (CGFloat *)feedDetailWithUpdate:(PostUpdate *)update
trackingInfo:(nullable TrackingInfo *)trackingInfo
highlightedComments:(NSArray<FeedComment *> *)highlightedComments
NS_SWIFT_NAME(feedDetailWithUpdate(update:trackingInfo:highlightedComments));
Run Code Online (Sandbox Code Playgroud) 我正在尝试解决我们在UITableViewCell. 有UIStackView带有子视图的嵌套,例如UILabel具有内在的内容大小。我创建这个示例是为了简化解释我的问题:
导致这些界面生成器错误:
Top Stack
View Need constraints for: Y position, height
Middle Stack
View Need constraints for: Y position, height
Bottom Stack
View Need constraints for: Y position, height
Run Code Online (Sandbox Code Playgroud)
UILabels 及其内在内容大小决定。UIStackView具有Fill对齐和分布属性。缺什么?我创建了一个托管在 GitHub 上的示例项目。
我窗口的XAML看起来像这样:
<Window x:Class="Binding1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Cronjobs" Height="350" Width="525">
<Grid>
<ListBox HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch" ItemsSource="{Binding Cronjobs}" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
可见我将ListBox绑定ItemsSource到当前Cronjobs属性DataContext.DataContext在代码隐藏的构造函数中设置为以下ViewModel的实例:
public partial class MainWindow : Window
{
private CronjobViewModel cronjobViewModel;
public MainWindow()
{
InitializeComponent();
this.cronjobViewModel = new CronjobViewModel();
this.DataContext = cronjobViewModel;
}
}
Run Code Online (Sandbox Code Playgroud)
ViewModel看起来像这样:
class CronjobViewModel : DependencyObject
{
public ObservableCollection<Cronjob> Cronjobs;
public CronjobViewModel( )
{
this.Cronjobs = new ObservableCollection<Cronjob>();
this.Cronjobs.Add( new Cronjob() );
this.Cronjobs.Add( new Cronjob() );
}
}
Run Code Online (Sandbox Code Playgroud)
为了快速简单的调试,我现在手动将一些项目添加到集合中.那Cronjob类是实际的模型,它只不过是一些简单的字符串属性,砍倒在主要部件的类的更多:
class Cronjob …Run Code Online (Sandbox Code Playgroud) swift ×5
xcode ×4
ios ×2
.net ×1
autolayout ×1
binding ×1
bridging ×1
c# ×1
foundation ×1
macos ×1
mvvm ×1
objective-c ×1
uistackview ×1
webkit ×1
webview ×1
wkwebview ×1
wpf ×1