IBOutlets on second view controller help on swift

2019-09-20 17:18发布

On my first view controller I had no problem creating IBOutlets and Actions, but when I made another view controller, I couldn't make an IBOutlet. There was no blue line when I control dragged it and I couldn't make an IBOutlet and then connect it up either. The first view controller still works. Is it possible to make IBOutlets on two different view controller?

3条回答
三岁会撩人
2楼-- · 2019-09-20 17:50

Your view controller must have a custom class file assigned to it in the identity inspector in InterfaceBuilder:

enter image description here

Then select the assistant editor and you should be able to ctrl-drag IBOutlets to the associated swift file.

查看更多
等我变得足够好
3楼-- · 2019-09-20 17:51

Make sure you have set the custom class for second view controller in your storyboard.

Custom class for second view controller

查看更多
你好瞎i
4楼-- · 2019-09-20 18:02

it happens to me sometimes as well... and the reason it to use the new controller you need to create a new view controller file for it where you can use the iboutlets generally.. so you will be having one view controller file for each view controller. and you can follow the steps to do that.enter image description here

  1. first of all delete the new view controller file if you have made any. and the new controller as well...
  2. go to file new file choose cocoa class and then next and then write the name of the class you want e.g. newcontroller and make sure you choose uiviewcontroller in the next option and then click next and create.
  3. create a new vie controller in the main.storyboard and then click on the new view controller and on the right hand side rename the class to newcontroller. once you Finnish all these three steps you will be able to use iboutlets for sure..

good luck..

查看更多
登录 后发表回答