I have tab view inside a navigation view is crashing without any reason.
its working without tab view seems to be bug....
Post
Replies
Boosts
Views
Activity
This project writen in SwiftUI 1.0, I want to convert to swiftUI 2.0 . it say (
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in UIKitCore/UIView.h may also be helpful.
Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(:) for msgDatas may be missing as an ancestor of this view.: file SwiftUI, line 0
Fatal error: No ObservableObject of type msgDatas found. A View.environmentObject(:) for msgDatas may be missing as an ancestor of this view.: file SwiftUI, line 0)
brother, it is work , when I click the chatcell, it throw error for " self.data.selectedData = i
self.data.show.toggle()"
struct Home: View {
@EnvironmentObject var data : msgDatas
@State var show: Bool = false
var body : some View{
ZStack{
Color("bg").edgesIgnoringSafeArea(.top)
NavigationLink(destination: Chat(), isActive: self.$show) {
Text("")
}
VStack{
topView()
}
}
}
}
struct topView : View {
var body : some View{
VStack{
HStack(spacing: 15){
Text("Chats").fontWeight(.heavy).font(.system(size: 23))
Spacer()
Button(action: {
}) {
Image(systemName: "magnifyingglass").resizable().frame(width: 20, height: 20)
}
Button(action: {
}) {
Image("menu").resizable().frame(width: 20, height: 20)
}
}
.foregroundColor(Color.white)
.padding()
GeometryReader{_ in
Main().clipShape(Rounded())
}
}
}
}
struct chatTopview : View {
@EnvironmentObject var data : msgDatas
@State var show: Bool = false
var body : some View{
HStack(spacing : 15){
Button(action: {
self.data.show.toggle()
}) {
Image(systemName: "control").font(.title).rotationEffect(.init(degrees: -90))
}
Spacer()
VStack(spacing: 5){
Image(data.selectedData.pic).resizable().frame(width: 45, height: 45).clipShape(Circle())
Text(data.selectedData.name).fontWeight(.heavy)
}.offset(x: 25)
Spacer()
Button(action: {
}) {
Image(systemName: "phone.fill").resizable().frame(width: 20, height: 20)
}.padding(.trailing, 25)
Button(action: {
}) {
Image(systemName: "video.fill").resizable().frame(width: 23, height: 16)
}
}.foregroundColor(.white)
.padding()
}
}
and chatCell:
struct chatCell : View {
var data : msgdataType
var body : some View{
HStack{
if data.myMsg{
Spacer()
Text(data.msg)
.padding()
.background(Color("bg"))
.clipShape(msgTail(mymsg: data.myMsg))
.foregroundColor(.white)
}
else{
Text(data.msg)
.padding()
.background(Color("txtbox"))
.clipShape(msgTail(mymsg: data.myMsg))
Spacer()
}
}.padding(data.myMsg ? .leading : .trailing, 55)
.padding(.vertical,10)
}
}
here it is I gave some code about it:
struct msgType : Identifiable {
var id : Int
var msg : String
var time : String
var msgs : String
var name : String
var pic : String
}
// I already made a sample data....
var msgs : [msgType] = [
msgType(id: 0, msg: "New Album Is Going To Be Released!!!!", time: "14:32", msgs: "2", name: "Taylor", pic: "p0")
]
I show all code, u are not intend to solve problems.
brother in all question u are just asking interesting question, but no any solution, pls I need help. it is clear question.
SceneDelegate:
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
// Create the SwiftUI view that provides the window contents.
let contentView = ContentView()
let msgdata = msgDatas()
// Use a UIHostingController as window root view controller.
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: contentView.environmentObject(msgdata))
self.window = window
window.makeKeyAndVisible()
}
}
here it is,
class msgDatas : ObservableObject{
@Published var show : Bool = false
@Published var selectedData : msgType = .init(id: -1, msg: "", time: "", msgs: "", name: "", pic: "")
}
I did not get it what u mean?
I solve problem, when I calling @State
struct Home: View {
@EnvironmentObject var data : msgDatas
@State var show: Bool = false
var body : some View{
ZStack{
Color("bg").edgesIgnoringSafeArea(.top)
NavigationLink(destination: Chat(), isActive: self.$show) {
Text("")
}
VStack{
topView()
}
}
}
}
All my code here, tnx to help me. When I write my code like that circle image in toolbar padding bottom. I want to fixed image in toolbar.
struct NatureView: View {
@State var search = ""
var borderColor: Color = Color("color")
var body: some View {
NavigationView() {
VStack(alignment: .leading, spacing:0){
HStack(spacing: 0){
Spacer()
TextField("Search", text: $search)
.padding(.vertical,5)
.padding(.horizontal)
.background(Color.gray.opacity(0.090))
.cornerRadius(30)
.frame(width: 330, height: 32)
Spacer()
NavigationLink(LocalizedStringKey, destination:SettingsView())
Image("image")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 32, height: 32)
.clipShape(Circle())
.overlay(Circle().stroke(Color("color"), lineWidth: 1))
}
Spacer()
}
VStack {
Spacer()
Button(action: {}) {
Image("image-white")
.padding()
.background(Color("color"))
.foregroundColor(Color.white)
.clipShape(Circle())
.frame(width: 40, height: 40)
.shadow(color: Color("color"), radius: 1, x: 0.0 , y: 0.0)
}
}
.frame(maxWidth: .infinity, alignment: .trailing)
.padding()
}
}
}
}
Definitely NavigationLink, when you click the image button, jumping any other page .
Hi, again :), I will try to explain again. I have custom image button in toolbar, when I click the image button, I want to navigate "NaturalView" for example. here - https://stackoverflow.com/questions/66586181/click-image-button-and-navigate-another-view-in-swiftui some one ask.
I have circle image button in toolbar, When I click the image button, I want to open new View.