有错误的新代码。这就是我得到的错误。我有2组数据,将按2组显示。地点1中有员工,地点2中有不同的员工。当我添加第二个雇员列表时,我在Loc2文件的Cannot convert value of type 'DataUI' to expected argument type 'Data
行收到错误NavigationLink(destination: DetailView(data: listedPeople)) {
。
希望这足以说明问题。
放入名为ContentView
的1个文件
struct Home: View {
var body: some View {
TabView {
loc1()
.tabItem {
VStack{
Image(systemName: "person.3.fill")
Text ("Location 1")
}
}
.tag(2)
loc2()
.tabItem {
VStack{
Image(systemName: "person.fill")
Text ("Location 2")
}
}
}
}
}
在文件2中放置名为loc1
struct Data: Identifiable{
var id = Int ()
let title, imageUrl, Dev, URL: String
}
struct loc1: View {
let data:[Data] = [
Data(id: 0, title: "Cook", imageUrl: "hh",Dev:"John", URL: "school"),
Data(id: 1, title: "Staff", imageUrl: "JJ",Dev:"Harper", URL: "home" ),
Data(id: 2, title: "Busser", imageUrl: "uu",Dev:"Matt", URL: "Table"),
Data(id: 3, title: "Host", imageUrl: "tt",Dev:"Jacob", URL: "Door")]
var body: some View {
NavigationView {
List(data) { listedPeople in
NavigationLink(destination: DetailView(data: listedPeople)) {
HStack{
Image(listedPeople.imageUrl)
.resizable()
.cornerRadius(12)
.frame(width:30, height:30)
VStack (alignment: .leading){
Text(listedPeople.title)
.font(.headline)
Text(listedPeople.Dev)
.font(.subheadline)
}
}
}.navigationBarTitle(Text("location 1"))
}
}
}
}
将代码放置在名为loc2
的新文件中(这是我的错误所在)
import SwiftUI
struct DataUI: Identifiable{
var id = Int ()
let title, imageUrl, Dev, URL: String
}
struct loc2: View {
let data:[DataUI] = [
DataUI(id: 0, title: "Cook", imageUrl: "hh",Dev:"Bob", URL: "school"),
DataUI(id: 1, title: "Staff", imageUrl: "JJ",Dev:"Joe", URL: "home" ),
DataUI(id: 2, title: "Busser", imageUrl: "uu",Dev:"Nick", URL: "Table"),
DataUI(id: 3, title: "Host", imageUrl: "tt",Dev:"Hunter", URL: "Door")]
var body: some View {
NavigationView {
List(data) { listedPeople in
NavigationLink(destination: DetailView(data: listedPeople)) {
HStack{
Image(listedPeople.imageUrl)
.resizable()
.cornerRadius(12)
.frame(width:30, height:30)
VStack (alignment: .leading){
Text(listedPeople.title)
.font(.headline)
Text(listedPeople.Dev)
.font(.subheadline)
}
}
}.navigationBarTitle(Text("Location2"))
}
}
}
}
创建一个名为DetailView
的新文件
import SwiftUI
struct DetailView : View{
var data: Data
var body: some View {
NavigationView{
List {
HStack{
Image(data.imageUrl)
.resizable()
.frame(width:70, height:60)
.clipShape(Circle())
.shadow(radius: 10)
.overlay(Circle().stroke(Color.black, lineWidth: 1))
VStack{
Text(data.title)
.font (.title)
HStack{
Image(systemName: "envelope.fill")
.resizable()
.frame(width:20, height: 15)
Text("Data.URL")
.font (.subheadline)
}
}
}.navigationBarTitle(Text("Data.title"))
}
}
}
}
答案 0 :(得分:0)
检查一下!
DELETE
FROM instructor i1
WHERE i1.salary < (SELECT AVG(i2.salary) FROM instructor i2
WHERE i2.department = i1.department);
答案 1 :(得分:0)
您混合使用了Data和DataUI ...这就是问题所在。我真的不知道为什么您定义了两个名称不同的结构,它们完全相同?
我更正了这个问题,现在它可以运行了,
这是解决方法:
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
loc1()
.tabItem {
VStack{
Image(systemName: "person.3.fill")
Text ("Location 1")
}
}
.tag(2)
loc2()
.tabItem {
VStack{
Image(systemName: "person.fill")
Text ("Location 2")
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct loc1: View {
let dataUI:[DataUI] = [
DataUI(id: 0, title: "Cook", imageUrl: "hh",Dev:"John", URL: "school"),
DataUI(id: 1, title: "Staff", imageUrl: "JJ",Dev:"Harper", URL: "home" ),
DataUI(id: 2, title: "Busser", imageUrl: "uu",Dev:"Matt", URL: "Table"),
DataUI(id: 3, title: "Host", imageUrl: "tt",Dev:"Jacob", URL: "Door")]
var body: some View {
NavigationView {
List(dataUI) { listedPeople in
NavigationLink(destination: DetailView(dataUI: listedPeople)) {
HStack{
Image(listedPeople.imageUrl)
.resizable()
.cornerRadius(12)
.frame(width:30, height:30)
VStack (alignment: .leading){
Text(listedPeople.title)
.font(.headline)
Text(listedPeople.Dev)
.font(.subheadline)
}
}
}.navigationBarTitle(Text("location 1"))
}
}
}
}
struct loc1_Previews: PreviewProvider {
static var previews: some View {
loc1()
}
}
struct DataUI: Identifiable{
var id = Int ()
let title, imageUrl, Dev, URL: String
}
struct loc2: View {
let dataUI:[DataUI] = [
DataUI(id: 0, title: "Cook", imageUrl: "hh",Dev:"Bob", URL: "school"),
DataUI(id: 1, title: "Staff", imageUrl: "JJ",Dev:"Joe", URL: "home" ),
DataUI(id: 2, title: "Busser", imageUrl: "uu",Dev:"Nick", URL: "Table"),
DataUI(id: 3, title: "Host", imageUrl: "tt",Dev:"Hunter", URL: "Door")]
var body: some View {
NavigationView {
List(dataUI) { listedPeople in
NavigationLink(destination: DetailView(dataUI: listedPeople)) {
HStack{
Image(listedPeople.imageUrl)
.resizable()
.cornerRadius(12)
.frame(width:30, height:30)
VStack (alignment: .leading){
Text(listedPeople.title)
.font(.headline)
Text(listedPeople.Dev)
.font(.subheadline)
}
}
}.navigationBarTitle(Text("Location2"))
}
}
}
}
struct DetailView : View{
var dataUI: DataUI
var body: some View {
NavigationView{
List {
HStack{
Image(dataUI.imageUrl)
.resizable()
.frame(width:70, height:60)
.clipShape(Circle())
.shadow(radius: 10)
.overlay(Circle().stroke(Color.black, lineWidth: 1))
VStack{
Text(dataUI.title)
.font (.title)
HStack{
Image(systemName: "envelope.fill")
.resizable()
.frame(width:20, height: 15)
Text("Data.URL")
.font (.subheadline)
}
}
}.navigationBarTitle(Text("Data.title"))
}
}
}
}