Advertisement
drsgon13

HelpNextView

Jun 4th, 2024 (edited)
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.82 KB | None | 0 0
  1.     func stream(_ aStream: Stream, handle eventCode: Stream.Event) {
  2.         print("stream event \(eventCode)")
  3.         switch eventCode {
  4.         case .openCompleted:
  5.             print("Stream opened")
  6.         case .hasBytesAvailable:
  7.             if aStream == inputStream {
  8.                 var dataBuffer = Array<UInt8>(repeating: 0, count: 1024)
  9.                 var len: Int
  10.                 while (inputStream?.hasBytesAvailable)! {
  11.                     len = (inputStream?.read(&dataBuffer, maxLength: 1024))!
  12.                     if len > 0 {
  13.                         let output = String(bytes: dataBuffer, encoding: .utf8)
  14.                         if nil != output {
  15.                             print("server said: \(output ?? "")")
  16.                             Вот тут я пытаюсь перейти на другой View меняя параметр
  17.                             TestView().load()
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.         ....
  23.     }
  24.  
  25. struct TestView: View {
  26.     @Environment(\.presentationMode) var presentationMode
  27.     @State private var showingAlert = false
  28.     @State private var name = ""
  29.     @State private var showLoading = false
  30.     @State var whImg: CGFloat = 250
  31.     @State var testBool = true
  32.     let json = """
  33.    {"command": 0, "device":"Test"}
  34.    """
  35.    
  36.     let chatRoom = TCP_Communicator()
  37.     var body: some View {
  38.         VStack {
  39.             HStack {
  40.                 Button(action: { self.presentationMode.wrappedValue.dismiss() }
  41.                        , label: {
  42.                     Image(systemName: "arrow.left")
  43.                     Text("Назад")
  44.                 })
  45.                 .foregroundColor(.white)
  46.                 Spacer()
  47.                 Button(action: { showingAlert = true }
  48.                        , label: {
  49.                     Image(systemName: "gear")
  50.                 })
  51.                 .foregroundColor(.white)
  52.                 .alert("Введите IP адрес сервера", isPresented: $showingAlert) {
  53.                             TextField("IP адрес сервера", text: $name)
  54.                                 .foregroundColor(.black)
  55.                             Button("OK", action: submit)
  56.                             Button("Отмена", role: .cancel) { }
  57.                         }
  58.             }.padding(.top, 5)
  59.         }.padding(.top, 0)
  60.         VStack {
  61.             Image("Image")
  62.                 .resizable()
  63.                 .frame(width: whImg, height: whImg)
  64.                 .imageScale(.large)
  65.                 .foregroundStyle(.tint)
  66.             if showLoading {
  67.                 VStack {
  68.                     VStack(spacing: 20) {
  69.                         ProgressView()
  70.                         Text(textLoading)
  71.                     }
  72.                     .background {
  73.                         RoundedRectangle(cornerRadius: 20)
  74.                         .fill(.black)
  75.                         .frame(width: 200, height: 200)
  76.                     }
  77.                     .offset(y: -70)
  78.                 }
  79.             }
  80.             Text(UIDevice.current.identifierForVendor!.uuidString)
  81.         }
  82.     }
  83.     func load() {
  84.         Сначала просто пытался сделать смену testBool.toggle()
  85.         Не переходил. Пытался через Biling тоже не получается
  86.         _ = fullScreenCover(isPresented: , content: {
  87.             TestOnlineView()
  88.         })
  89.     }
  90.     func submit() {
  91.         print("You entered \(name)")
  92.         if(name != "") {
  93.             UserDefaults.standard.set(name, forKey: "ip_adres")
  94.             urlStr = URL(string: name)!
  95.             chatRoom.connect(url: urlStr, port: 2323)
  96.             chatRoom.send(message: json)
  97.             whImg = 200
  98.             showLoading = true
  99.         }
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement