It’s me. Right.
Hello.ENTP.World
It’s me. Right.
전체 방문자
오늘
어제
  • 분류 전체보기 (45)
    • 멋쟁이사자처럼 앱스쿨 1기 (18)
    • 2024 Apple Developer Academ.. (10)
    • 개발 with Apple (8)
    • Flutter (1)
    • 알고리즘 (4)
    • 디자인 (0)
    • 앱스토어 출시 (1)
    • 영어공부 (3)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • xcoud cloud cicd
  • 코테
  • xcode cicd
  • 백준
  • swiftUI
  • 협업
  • xcode 배포 자동화
  • 코딩테스트
  • xcode cloud appstoreconnect
  • 애플디벨로퍼아카데미
  • 알고리즘
  • Apple Developer Academy
  • 개발
  • 개발자
  • xcode 팀 계정
  • Xcode
  • 애플아카데미
  • Xcode cloud
  • 좋은 회고
  • git xcode cloud
  • swift cicd
  • 아키텍처
  • xcode cloud workflow
  • git cicd
  • 회고
  • ios
  • git xcodecloud
  • xcode cloud 계정 권한
  • 동기
  • xcodcloud

최근 댓글

최근 글

티스토리

반응형
hELLO · Designed By 정상우.
It’s me. Right.

Hello.ENTP.World

[오류] Alert 다중 사용 시 1개만 실행되고 나머지는 실행 안됨
개발 with Apple

[오류] Alert 다중 사용 시 1개만 실행되고 나머지는 실행 안됨

2024. 4. 18. 23:17
반응형

1. 내용 캡쳐

- 기존에 생각한 방식은 텍스트를 입력할 수 있는 Alert가 먼저 나오고, 텍스트 입력 후 '완료' 버튼을 누르면 해당 값이 기존에 생성된 Tag값과 같은지 확인하여 같은 경우 이름 중복에 대한 Alert가 뜨는 프로세스를 생각하였다.

따라서 아래와 같이 태그 생성 버튼에 텍스트 입력이 가능한 Alert를 생성해주었고, Alert 내부의 '완료' 버튼 클릭 시 태그 중복 여부 체크 후 Alert를 생성해주었습니다. 하지만 첫번째 텍스트 입력 Alert만 실행되고, 두번째 Alert가 실행되지 않았습니다.

 

 

2. 원인 분석

https://yyomzzi.tistory.com/m/8

 

[Issue 해결] SwiftUI에서 하나의 뷰에 여러 개의 Alert 나타내기

오느른..~ swiftUI로 앱을 만들다가 만나게 된 이슈를 해결한 과정을 보여드릴까 합니댜 swiftUI로 몇 가지 아~주 작은 앱들을 만들어 보면서 최근에 배우게 된 Alert를 많이 사용하게 되는데 그을쎄

yyomzzi.tistory.com

해당 게시글을 기반으로 확인해보니, 하나의 View에는 1개의 Alert만 작동하는 것을 확인하였습니다. 저의 경우 Tag를 만들어주는 한 개의 Button(즉 View) 하위에 Alert가 2개의 depth로 붙어있는 형식이기 때문에 상위의 1개만 실행되 되는 것으로 판단하였습니다.

 

3. 결과

그렇다면 Button과 다른 View에 Alert를 설정해준다면 가능할 것이라고 생각했습니다.

'완료' 버튼 클릭하게 되면 기존의 태그와 같은지 확인 후 같다면 Button이 포함되어 있지만 현재 상태에서 가장 하위뷰에서 중복 여부 Alert를 실행시켜줍니다. 태그 이름 중복 시 첫번째 Alert가 사라진 후 중복에 관한 두번째 Alert까지 잘 나오는 것을 확인할 수 있습니다.

(문제는 해결했지만 디자인, 프로세스적인 고민으로 중복 Alert는 결국 이번 프로젝트에 사용하지 않았습니다.)

import SwiftUI

struct ContentView: View {
    @State private var tags : [String] = ["의료"]
    @State private var showInputNewTag : Bool = false
    @State private var showSameName : Bool = false
    @State private var name : String = ""
    var body: some View {
        VStack {
            Button(action: {
                showInputNewTag.toggle()
            }, label: {
                Text("태그 생성 버튼")
            })
            .alert("새로운 태그 입력", isPresented: $showInputNewTag) {
                TextField("태그를 입력해주세요", text: $name)
                Button(action: {
                    
                }, label: {
                    Text("취소")
                })
                Button(action: {
                    if tags.contains(name) {
                        showSameName.toggle()
                    }
                }, label: {
                    Text("완료")
                })
            } message:{
                Text("새로운 태그를 입력해주세요")
            }
        }
        .alert("중복 태그 알림", isPresented: $showSameName, actions: {
            Button(action: {
                
            }, label: {
                Text("확인")
            })
        })
        .padding()
    }
}

 

반응형

'개발 with Apple' 카테고리의 다른 글

[오류] SwiftData - Accessing Environment<ModelContext>'s value outside of being installed on a View. This will always read the default value and will not update. & View outside에 위치한 @Query를 사용하여 데이터 불러오기 실패  (3) 2024.05.31
[오류] Local Authentication 보라색 오류 발생 - Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.  (4) 2024.04.19
[오류] MacOS 업그레이드 후 개발자도구 xcrun: error: invalid active developer path  (1) 2023.11.22
[오류] Xcode - The run destination is not valid for running the scheme  (6) 2023.11.03
[공부] 인프런 UIKit 강의 - 6가지 Passing Data 방식  (3) 2023.05.10
    '개발 with Apple' 카테고리의 다른 글
    • [오류] SwiftData - Accessing Environment<ModelContext>'s value outside of being installed on a View. This will always read the default value and will not update. & View outside에 위치한 @Query를 사용하여 데이터 불러오기 실패
    • [오류] Local Authentication 보라색 오류 발생 - Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.
    • [오류] MacOS 업그레이드 후 개발자도구 xcrun: error: invalid active developer path
    • [오류] Xcode - The run destination is not valid for running the scheme
    It’s me. Right.
    It’s me. Right.
    개발자가 되고싶은 코린이의 천방지축 얼렁뚱땅 개발일기

    티스토리툴바