[ad_1]
I’ve Scrollview_Itemselect was written by swiftUI. I attempt to cross an motion from this struct to my UIViewController CLASS_A’s WBMode_change func. It really works OK however I bought an uncommon drawback when I attempt to convert Int to String.
struct Scrollview_Itemselect: View { //struct
@State var emojisArray = ["A", "B", "C", "D"]
@State var selectedIndex = 0
let someView = CLASS_A()
var physique: some View {
VStack {
ScrollView(.horizontal) {
HStack {
ForEach(0..<emojisArray.depend) { merchandise in
emojiView(emoji: self.emojisArray[item],
isSelected: merchandise == self.selectedIndex ? true : false)
.onTapGesture {
// print (merchandise)
self.selectedIndex = merchandise
// Name func in CLASS_A()
self.someView.WBMode_change(mode: self.selectedIndex)
}
// .body(width: 100, top: 120)
}
}
}
}
}
}
//right here is my class, I describe WBMode_change right here.
//WBMode_change shall be referred to as above, inside Scrollview_Itemselect struct.
//[self.someView.WBMode_change(mode: self.selectedIndex)]
Class CLASS_A: UIViewController, UIScrollViewDelegate { //my class
func WBMode_change(mode:Int){
print("consequence", mode:Int) // print OK
lbl_WBMode.textual content = String(mode) //ERROR right here
}
}
I bought the print consequence positive however bought “unexpectedly discovered nil” when changing mode to String.
Then I modified some issues and tried this code under.
Class CLASS_A: UIViewController, UIScrollViewDelegate {
//nonetheless error even I do not use "mode" variable
func WBMode_change(mode:Int){ //get motion from struct swiftUI
let mode_number:Int = 10
print("mode_number", mode_number)
lbl_WBMode.textual content = String(mode_number)
}
//no error
func test_mode(){ //do not get motion from struct swiftUI
let mode_number:Int = 10
print("mode_number", mode_number)
lbl_WBMode.textual content = String(mode_number)
}
}
It nonetheless error after I simply put a textual content on it like this
lbl_WBMode.textual content = “Whats up”.
Is there anybody who is aware of what sort of this drawback is?
[ad_2]
