Programing

Xcode 4 : UIView xib 만들기, 제대로 연결되지 않음

lottogame 2020. 9. 17. 18:49
반응형

Xcode 4 : UIView xib 만들기, 제대로 연결되지 않음


TableViewCell에 포함될 뷰가 포함 된 펜촉을 만들려고합니다. 인터페이스 및 구현 파일을 만들었 ResultCell.h으며 ResultCell.m. 재고, 즉시 사용 가능하며 코드 변경이 없습니다.

그런 다음 빈 XIB 파일을 만들고 UIView를 끌어 놓습니다. 그런 다음 파일 소유자를 클릭하고 유형을 ResultCell. 보기를 클릭하고 해당 클래스도 ResultCell.

내가 가진 문제는 다음과 같습니다.

  1. 내가 살고있는 Assistant Editor보기를 ResultCell.h사용할 때 ResultCell.xib 파일을 볼 때 파일이 나타나지 않습니다. 자동을 클릭하고 파일을 선택하여 강제로로드해야합니다.
  2. 보기에 레이블을 놓은 다음 Ctrl + 클릭하고 .h로 끌어서 콘센트를 만들면 다음 오류 메시지가 표시됩니다. " 새 콘센트 연결을 삽입 할 수 없습니다. ResultCell이라는 클래스에 대한 정보를 찾을 수 없습니다. "

뷰를 만들고 다시 만들려고했지만 작동하지 않고 인내심을 잃기 시작했습니다. 어떤 도움이라도 대단히 감사하겠습니다!


특정 문제에 대해서는 작동하지 않을 수도 있지만 새로 생성 된 펜촉으로 작업 할 때 가끔 해당 오류가 발생합니다. 이전과 같은 이름을 가진 펜촉과 뷰 컨트롤러를 삭제하고 다시 생성해도 문제가 해결되지 않았지만 Xcode를 다시 시작하면 해결되었습니다.


오늘도 비슷한 상태가되었습니다. 매우 이상했습니다. 프로젝트에 이미 존재하는 ViewController 클래스에 XIB (신규 또는 기존)를 연결할 수 있었지만 새 ViewController를 만들고 XIB에 제대로 연결하지 못했습니다. "보조"기능이 작동하지 않았고 IB- 헤더 파일 연결 기능도 작동하지 않았습니다.

프로젝트를 닫고 다시 열어도 문제가 해결되지 않았습니다.
XCode를 종료하고 다시 시작해도 문제가 해결되지 않았습니다.
새 프로젝트를 만들고 기능을 테스트하는 것이 잘 작동하여 어딘가에 캐시에 뭔가 손상된 것이 있다고 생각했습니다.

내 솔루션

  • 프로젝트를 닫으십시오.
  • ~ / Library / Developer / XCode / DerivedData 폴더로 이동하여 작업중인 프로젝트를 참조하는 모든 하위 폴더를 제거합니다.
  • XCode에서 프로젝트를 엽니 다. 이제 문제가 해결되어야합니다.

덧붙여서, 전체 청소를 실행하는 것만으로는 문제가 해결되지 않는 것 같습니다. 파생 된 데이터를 폐기해야했습니다. 나는 내가 플레이하고 있던 git 게임 때문에이 위치에 들어갔다고 확신하지만, 이전 git 개정으로 다시 전환해도 도움이되지 않았기 때문에 어떻게 빠져 나올지 몰랐다. (그것은 또한 프로젝트 자체에서 추적되지 않은 무언가라는 큰 단서였습니다.)


나는 방금이 문제가 있었고 Xcode를 다시 시작해도 문제가 해결되지 않았습니다. 프로젝트에서 클래스 파일을 제거한 다음 다시 추가하고 작동하기 시작했습니다.


나는 똑같은 문제가 있었다. 그리고 나는 시도했다 :

  • Xcode 다시 시작
  • 파생 데이터 삭제
  • 그리고 더 많은

그 어느 것도 효과가 없었습니다. 나를 위해 일한 것은 단순히 다음과 같습니다.

  • 프로젝트에서 '의심스러운'클래스 파일을 제거합니다 (참조 만 제거합니까?)
  • 프로젝트에 다시 추가

그리고 끝났습니다!


Xcode를 다시 시작해도 작동하지 않으면 새 .m 파일을 대상 멤버로 전환했다가 다시 전환하는 것이 작동한다는 것을 알았습니다.


이것은 나를 도왔습니다.

  1. 프로젝트 파일 패널 (왼쪽)에서 깨진 xib 파일을 선택합니다.
  2. 편집기보기에서 파일 소유자 아이콘을 클릭하십시오.
  3. 속성 패널 (오른쪽)에서 세 번째 탭 (상단)을 선택합니다.
  4. "사용자 정의 클래스"지정

"패널"이 보이지 않으면 창의 오른쪽 상단을보고 적절한 "보기"버튼을 활성화하십시오. "보기"버튼이 보이지 않으면 오른쪽 상단의 캡슐 버튼을 클릭하십시오.


.m 파일이 en.lproj 폴더로 이동 한 것을 확인했습니다.

Xcode에서 .m 파일을 삭제 (참조 전용)하고 en.lproj에서 .m을 이동했습니다. 다시 추가하면 문제가 해결됩니다.

걱정하지 마세요. 모든 연결이 복구됩니다.


오늘도 같은 문제가 발생했습니다. XCode를 다시 시작해도 문제가 해결되지 않았습니다. Organizer 에서 찾을 수있는 프로젝트"파생 데이터""삭제" 옵션을 사용하여 작업을 정상으로 되돌릴 수있었습니다 . Organizer는 "파생 데이터에는 색인, 빌드 출력 및 로그가 포함됩니다"라고 말합니다. 나도 추측 인덱스 또는 빌드 출력이 이 문제를 일으키는 원인이되었다.


XCode에서 주최자로 이동하여 프로젝트를 클릭하고 파생 데이터 삭제를 클릭합니다. 프로젝트를 정리하는 것보다


제 경우에는 해당 헤더 파일에 "가짜 변경"(공백)을 만드는 데 도움이되었습니다.


  1. ResultCell은 다음의 하위 클래스 여야합니다. UITableViewCell
  2. UIView빈 캔버스로 드래그해서는 안됩니다.UITableViewCell
  3. 셀을 선택하고 하위 클래스로 변경 해야 합니다.
  4. 소유자는 대부분 셀에 대한 콘센트가있는 컨트롤러입니다.

새 셀을로드 할 때마다 다음을 호출하십시오.

 [[NSBundle mainBundle] loadNibNamed:nibName 
                               owner:controllerWithOutletToCell 
                             options:nil]

로드 후 셀을 사용하고 ivar / outlet을 nil로 설정하여 다음로드를 준비합니다.

다른 방법이 있지만 이것은 일반적입니다


아마도 저에게 효과가 있었던 것은이 .. (Xcode v4.5)

이것은 작동하지 않았다

내 .h의 인터페이스 정의로 드래그를 제어하려고했습니다.

@interface SearchViewController : UIViewController

@end

이것은 효과 가 있습니다 (예상했던 방식 수 있습니다. 전에는 몰랐습니다) 열기 및 닫기 괄호를 참조하십시오. 닫힌 괄호 뒤의 드래그 앤 드롭을 제어합니다.

@interface SearchViewController : UIViewController
{
}

@end

Swift로 작성된 프로젝트에서 비슷한 문제가 발생했습니다.

What worked for me was setting up the IBOutlet in code like this

@IBOutlet var foo: UIView?

and afterwards connect it to Interface Builder by dragging to the little circle that appeared right next to the code line.


None of the above workarounds resolved the connector issue for me so I shelved my pet project until I came across the following stackoverflow thread:

https://stackoverflow.com/a/15873770/2846800

I had been working on a large project in a previous version of XCode and had turned off indexing. By re-enabling indexing my issue is now fixed:

defaults delete com.apple.dt.XCode IDEIndexDisable

I can now use the D&D features of Interface Builder. I hope this can help others...


This problem seems to be an Xcode bug which creeps up mostly when you replace a file with a new file of the same name. Xcode seems to keep a reference of the older file of the same name.

Anyhow, the way to fix this seems to be:

  1. Clean the project
  2. Click (Your Project) in Project Navigator view. Go to Compile Sources under Build Phases of the target for which you are building. Remove and add back the .m file which is giving you trouble.
  3. Alternatively, in the File Inspector (Utilities view) of the NIB file, under Target Membership, uncheck and check back the target name.
  4. Restart Xcode for good measure.
  5. Of course, deleting and adding back the .m file alone should fix it too.

(Steps 1 and 2 alone fixed it for me.)


If you copied files from other project just make sure you check the 'Add to targets' box


Renaming the class files may unlink them from the XIB. This answer helped me discover this:

Ctrl-Drag from button to method not working. Xcode/Interface Builder

Check that your custom class is set correctly in the Identity Inspector.


Similar symptom, but different cause.

Apparently I hit backspace when the focus was on the assistant view, because one of the standard file template comment lines went from // to / which results in the file not compiling.

Fixing the comment allowed the SDK to parse the file, recognize it as a UIViewController, and add in the outlet.

SO -- if you have this problem, do a build or analyze to see if there are errors that need fixing in your view controller .h file. THEN try the other solutions.


This might be an old topic but just in case anyone has the same issue in future, try deleting the associated .xib,.h and .m files and create new ones. For me, the UIViewController in my .h file wasn't purple and even backspacing and typing it didn't help.


Just put a line between the @implementation and the @synthesize. Most of the answers here have that in common. It worked for me

@implementation 

@synthesize

I just tried everything here and nothing worked (using a Developer Preview for Xcode 5).

The only thing that worked for me was to put this incomplete line in my interface file:

@property (nonatomic, weak)

For whatever reason, adding outlets and actions by drag and drop from a .xib worked fine after that.


For me wether cleaning nor deleting the DerivedData solved the problem.

I tried to delete and recreate my UIViewController class several times and got the problem again and again.

Then I recreated the UIViewController class and gave it a different name. This solved the problem for me.


I have had this problem and found a solution not listed above.

In my case, I could see there was something wrong in the class .h file because my custom view controller did not recognise the class : UIViewController (it was in black not purple). All the other custom view controllers had the : UIViewController in purple.

in my case, and possibly yours, I needed to add the class to targets/build phases/compile Sources drop down. The .m needs to be added. All of the other .m's were there but not this one.

Once I added it, the :UIViewController appeared in purple and everything worked fine.


For my case, I have multiple project with some other dependencies. I tried to solve it by deleting derived data or restarting XCode but it couldn't work. In the end, I tried the following method and it works:

Go to target > Build Target Architectures Only > and set both Debug and Release to NO.

Set this for all projects in the workspace and recompile to make sure there is no other errors. Maybe not making sense but somehow did it. During my compilation, I had other issues such as linker errors and symbols not found.


For *.m file of this class view open "Show File Inspector" and unchecking "Target membership" for this project, then do Clean (menu Product->Clean) and checking again "Target membership" for this project

enter image description here


Using Swift, I had a similar problem. I found out that the comments were part of the problem for me.

I leveraged the default view controller, did some work in it, then created a second view controller by copying the entire first one, stripping it down to only viewDidLoad() and renaming the class to TestViewController. Builds worked, code executed. All was good.

When I went to drag a UITextField in to create an outlet, it would not let me. I noticed that my comments still said "ViewController.swift", so I changed the comment text to "TestViewController.swift" and rebuilt. I was able to connect my outlet!

I wonder if what occurred is that the Indexer was reading the comments as well as the class names, and somehow got confused.


Hope this helps someone out there.

I just had to delete the derived data folder. You need to click Window -> Organizer -> Projects -> Delete Derived Data

AND RESTART XCODE.

You should be good to go!


The new class not being part of the "TARGET" is likely the root cause of this, as alluded to by some of these answers.

When creating a new cocoa class, by default the option to add new class to target is by default checked, but should, for any reason, this not be checked when you hit save, you will have this issue.

New Class Target

Any of these workarounds that add the new class to the apps target will work to resolve the problem, and is something that all these 'fixes' have in common.

I think XCode likely has some bugs that causes a new file to, by default, NOT be added to the apps main target. The fix boils down to adding your 'broken' class to the main TARGET


In XCode 7.1, adding the connector at a different point in my source file worked. The error I was getting referred to one of my variables as if it were a class (didn't make any sense). The error stopped occurring when I added the connector below that variable instead of above it.


There is also a diferent reason for the issue ... if you have created new cocoa class file with template other than ios ... i can happen...

The solution would be to delete it and re create it with right template enter image description here

참고URL : https://stackoverflow.com/questions/6703054/xcode-4-creating-a-uiview-xib-not-properly-connecting

반응형