简体   繁体   中英

how to remove all references for outlet

I accidently set event for command button as "outlet" than "action". Due to auto-drag feature, xcode generated references in applicationDelegate and .h and .m files. I removed the entry from .h and .m files but simulator wont run because it is still looking for that missing reference. I could not find that outlet referred anywhere. I am fairly new to iOS programming. Can anyone suggest a solution for this?

You have to unlink the outlet from the item in interface builder. Select the UI element that you linked the outlet to and then remove it in the "Connections Inspector".

在此输入图像描述

Click the little "x" ^^^

I think there are two different reasons that people may come here wondering how to get rid of an unwanted Outlet reference.

  1. Created an unwanted outlet while using the Interface Builder.
  2. Copied some Outlet code from another projects View Controller.

Both reasons are fairly easy to solve.

Unwanted Outlet in IB

Method One

Right click the view in the storyboard and then click the little x by the referencing outlet.

在此输入图像描述

Method Two

Right click the view name in the Document Outline. Then click the little x by the referencing outlet.

在此输入图像描述

Method Three

Select the view on the storyboard and then click the Connections Inspector. Then you can click the little x to remove an outlet reference.

在此输入图像描述

Unwanted Reference in Code

If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets!

在此输入图像描述

If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.

Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Use the methods in part one of this answer to see if a view in your current project has a referencing outlet or not.

No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior. The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore it.

It will be listed in the storyboard/xib as well, on the command button outlets.

Delete it from there as well, and you should be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM