BindableObjects到目前为止,我一直在使用SwiftUI并了解etc 的概念(至少我希望我这样做)。
我遇到了一个愚蠢的问题,似乎找不到以下答案:如何初始化@Binding变量?
我有以下代码:
struct LoggedInView : View {
@Binding var dismissView: Bool
var body: some View {
VStack {
Text("Hello World")
}
}
}
Run Code Online (Sandbox Code Playgroud)
在我的预览代码中,我想传递以下类型的参数Binding<Bool>:
#if DEBUG
struct LoggedInView_Previews : PreviewProvider {
static var previews: some View {
LoggedInView(dismissView: **Binding<Bool>**)
}
}
#endif
Run Code Online (Sandbox Code Playgroud)
我将如何进行初始化?尝试过:
Binding<Bool>.init(false)
Binding<Bool>(false)
Run Code Online (Sandbox Code Playgroud)
甚至:
@Binding var dismissView: Bool = false
Run Code Online (Sandbox Code Playgroud)
但是没有一个...有什么想法吗?
我一直在搜索这个错误,并找到一些具有类似行为的帖子,但没有解决问题的解决方案.
我有一个UITableViewController(在SB中声明为Static),它有章节:Section 0(Recipe)是静态的4个单元格,Section 1(Flavors)应该是动态的

这是我用来测试的代码:
- (void)viewDidLoad {
[super viewDidLoad];
rows = [[NSMutableArray alloc] initWithArray:@[@"test",@"test",@"test",@"test",@"test",@"test",@"test"]];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
switch (section) {
case 0:
return 4;
break;
case 1:
return rows.count;
break;
default:
break;
}
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
switch (indexPath.section) {
case 0:
return [super tableView:tableView cellForRowAtIndexPath:indexPath]; …Run Code Online (Sandbox Code Playgroud)