Development Tip

스토리 보드 UIViewcontroller, '사용자 정의 클래스'가 드롭 다운에 표시되지 않음

yourdevel 2020. 12. 7. 20:57
반응형

스토리 보드 UIViewcontroller, '사용자 정의 클래스'가 드롭 다운에 표시되지 않음


내 앱 스토리 보드에서 만든 UIViewController와 프로젝트에 추가 한 사용자 지정 UIViewController 하위 클래스가 있습니다 (그리고 내 대상의 컴파일 단계에 있음). 그러나 Storyboard의 뷰 컨트롤러에서 'Custom Class'속성을 설정하려고하면 내 사용자 지정 클래스가 목록에 표시되지 않습니다.

  • 클래스가 테스트가 아닌 내 앱 대상의 일부인지 확인했습니다. '
  • UIViewController의 하위 클래스인지 다시 확인했습니다.
  • xcode가 최신 정보로 작동하는지 확인하기 위해 컴파일 된 프로그램
  • 다시 시작된 xcode

내 클래스가 '사용자 지정 클래스'드롭 다운에 표시되지 않는 이유는 무엇입니까?


문제를 해결하는 두 가지 방법을 찾았지만 해결 방법입니다. 1. 텍스트 필드에 뷰 컨트롤러 이름을 입력하거나 2. 프로젝트를 닫은 다음 다시 열고 프로젝트 초기화에서 파일을 목록에 배치합니다.


여전히 문제가 있거나 같은 문제를 겪을 수있는 사람들을 위해 :

스토리 보드에서 "View"(스토리 보드에서보기를 클릭하면 자동으로 선택됨) 대신 "ViewController"를 선택해야합니다. 이 둘의 차이점은 뷰 컨트롤러를 선택하면 앱 주위에 파란색 사각형이 팝업된다는 것입니다. 보기 컨트롤러를 선택하려면 문서 개요를 열고 스토리 보드 계층 구조에서 직접 선택하십시오.

여기에 이미지 설명 입력 여기에 이미지 설명 입력 여기에 이미지 설명 입력


다음을 시도합니다.

  1. 클래스를 구현하는 파일이 빌드 단계의 일부인지 확인합니다 ( target > build phases 아래에서 확인 ).
  2. 빌드 단계에.m 파일을 추가합니다 (아직없는 경우).
  3. Xcode를 다시 시작하십시오.

스토리 보드의 XML을 편집하여이 문제를 해결할 수 있습니다.

  1. 프로젝트 네비게이터 패널 My.storyboard에서 항목을 마우스 오른쪽 버튼으로 클릭 하고 다른 이름으로 열기-> 소스 코드 메뉴 항목을 선택합니다. XML에서보기 컨트롤러 항목을 찾고 속성을 추가하십시오 .customClass="MyController"

  2. 스토리 보드를 저장하십시오.

  3. 프로젝트 네비게이터 패널 My.storyboard에서 항목을 다시 마우스 오른쪽 버튼으로 클릭 하고 다른 이름으로 열기-> 인터페이스 빌더-스토리 보드 메뉴 항목을 선택합니다.

이제 사용자 정의 클래스 항목에 MyController클래스 이름이 포함됩니다 .


클래스가 UIViewController에서 상속되는지 확인하십시오.

@interface ClassName : UIViewController

Xcode 8에서 내 클래스 중 일부는 파일 위치에 대해 잘못된 경로 (대소 문자 구분)를 지정했습니다.

MyProject/mysubdirectory/MyViewController.xib (.m, .h)

대 :

MyProject/MySubdirectory/MyViewController.xib (.m, .h)

그 상태에서 어떻게 끝났는지 확실하지 않지만 내 프로젝트는 위와 똑같은 동작을 보였고 (IB에 콘센트 / 작업이 표시되지 않음) 해당 경로를 수정하면 문제가 해결되었습니다.

이 두 가지 방법을 수정했습니다. 한 가지 방법은 .pbxproj 파일을 열고 대소 문자 구분 문제를 수동으로 수정하는 것입니다. 다른 방법은 파일의 파일 검사기 탭에있는 ID 및 유형 섹션 아래에있는 폴더 아이콘을 누르고 거기에서 파일을 다시 선택하는 것입니다.


이 문제에서 설명한 것과 동일한 문제가 발생했습니다. 그러나 제안 된 답변 중 어느 것도 나를 위해 수정하지 않았습니다. 내 프로젝트는 경고 나 오류없이 정상적으로 컴파일되었지만 .h 파일에는 내 콘센트가 스토리 보드 요소에 연결되었음을 나타내는 '아울렛'표시기가 없습니다.

또한 내 코드에서 마우스 오른쪽 버튼을 클릭하고 내 헤더 파일로 드래그하여 새 아웃렛을 생성하려는 시도는 내 헤더 소스를이 작업의 잠재적 대상으로 인식하지 못했습니다. 또한 내 클래스는 ViewController의 속성 관리자 패널에 대한 Custom-Class 드롭 다운에 나타나지 않았습니다.

그러나 프로젝트는 정상적으로 컴파일되었습니다.

자세히 살펴보면 다음과 같은 방식으로 내 클래스를 정의한 것으로 나타났습니다.

@interface KJBMainDataViewTrackConMk2<UIScrollViewDelegate> : UIViewController

잘 컴파일됩니다.

그러나 이것이 다음과 같이 변경되면 (프로토콜을 끝으로 이동) ...

@interface KJBMainDataViewTrackConMk2 : UIViewController<UIScrollViewDelegate>

그러면 모든 것이 살아납니다. 모든 콘센트가 갑자기 스토리 보드 요소와 '연결'된 것으로 표시됩니다. 그리고 오른쪽 클릭 드래그가 다시 작동하기 시작하고 스토리 보드 ViewController의 속성 관리자 패널에있는 사용자 정의 클래스 드롭 다운에 사용자 정의 클래스가 나타납니다!

여기에있는 다른 답변은 아마도이 상태의 가장 가능성있는 원인을 나타낼 수 있지만, 적어도이 다른 잠재적 원인을 언급 할 가치가 있다고 느꼈습니다.


스토리 보드에서 다른 뷰 컨트롤러를 클릭 한 다음 사용자 지정 클래스 풀다운을 클릭하여 새 클래스가 나열되었는지 확인하지만 선택하지는 마십시오. 만든 새 뷰 컨트롤러를 다시 클릭하면 사용자 정의 클래스 풀다운 메뉴에 나열됩니다. 이상 하죠? 제 생각에 새로 고침을 강요합니다.


I had the same problem, but none of the other solutions worked for me. The issue for me was that I had a Mac and iOS target, both with their own versions of the same view controller. For example, I had a .h/.m pair of files named FooViewController for Mac and another .h/.m pair of files named FooViewController for iOS. Each pair was properly included with their respective targets, but for some reason Xcode does not like it and my view controller would not show up in the Custom Class dropdown in the view controller in the storyboard. I ended up renaming my class in the iOS view controller and it immediately showed up in the dropdown.


In my case, I drag a new TableViewController object to the storyboard, but I add a new file which's subclass is "UIViewController".... Then, I add a file which's subclass is "UITableViewController", problem solved!!


I happened to come across this problem, and had no luck after trying the previous suggestions. Finally I found the reason is the header file's type is set to C++ header. After changing it to C header (like all the other header files), the class appears in the drop list. Don't know why though... Possibly helpful for others so I post it here.


For those of you who are still having this problem after trying all the way around is probably because you clicked the View instead of ViewController.

You have to choose the file when ViewController is clicked.

This solved my problem.

여기에 이미지 설명 입력


be sure initially not adding the CustomViewController to any group or folder. place it in the root of your app.


none of the above(or below :) helped me. though I found that

  1. after adding new viewcontroller to storyboard (just by dragging it in)
  2. and adding my class by File\New\File\Objective-C Class, give it a name, no XIB, Next, Create

if I select my viewcontroller in storyboard and try to assign my class to it - my class is not there

BUT

if I click on a view that is in the viewcontroller itself then click on a class dropdown menu in Custom Class

AND THEN

select viewcontroller (click on a bar below the viewcontroller) and now again click on a class dropdown in Custom Class my newly added class magically shows up.

weird, must be a bug with refreshing. Xcode Version 5.1 (5B130a)


Make sure you select View Controller to which you want to attach your class. The easy way is open Document Outline and choose your view controller (When you tap on it form the Storyboard sometimes it simply doesn't choose the object you meant).


Storyboard is looking for the custom class but physically its no there and its not displaying the custom class name in the list and also not displaying the outlets . Following solution perfectly worked for me.

  1. Just copy your code some where else.(Lets say on desktop)
  2. Open your existing code.
  3. Delete the custom class file.(Move to trash)
  4. Now add files from copied project folder (From desktop)
  5. Don't forget to check "Copy if needed" check box
  6. Open the story board and bingo you will get your custom class files in dropdown

for my case, somehow bundle resources got deleted, so I added back and worked!

Build Phases -> Add Build Phase -> Copy Bundle Resources find your file Then drag and drop your file there

Then make sure your target membership is checked.


In my case, I selected the wrong UI.. so I deleted the class file and created a new one and selected the correct parent class


I had to restart XCode 7.3 (7D175)


What worked for me was, click on the file in the Project Navigator, then, in the File Inspector under "Identity and Type" beneath the "Location" dropdown box, click on the little folder icon and then select the file in the popup window.


Try to clean your project, and also restart your Mac. One peculiar thing that I did was change all the Custom Classes names and build the project again. It worked!


For macOS projects, creating a new class generated a class inheriting from NSObject instead on NSViewController.

Change from

import Cocoa

class AppsViewController: NSObject {

}

to

import Cocoa

class AppsViewController: NSViewController {

}

I was fairly frustrated with this issue as none of the answers above had solved my problem.

In my case: I was in the middle of working on swift view controller file and was making active changes (such as creating a custom collection cell class). I had not finished the code block and left it open like so :

class tableViewCell: UITableViewCell { 
}
class collectionCell: 


class viewController: UIViewController {
     override func viewDidLoad(){
     super.viewDidload()

     }

}

Note the incomplete code block 'collectionCell2' This was enough for xcode to not recognize my viewController file as such. Once I completed this block the file reappeared in my xcode as an option.

Very silly and simple.


Make sure the class name of the ViewController is the name that you want. i.e.

class MyCustomNameViewController: UIViewController {
.
.
} 

Changing just the filename is not enough.

참고 URL : https://stackoverflow.com/questions/14130184/storyboard-uiviewcontroller-custom-class-not-showing-in-drop-down

반응형