Xcode 4.3: duplicated connections of an IBOutlet

随声附和 提交于 2020-01-02 08:43:48

问题


I am learning Stanford CS193p course with Xcode 4.3.3. I think the screenshot below is pretty much self-explaining. But i will describe the problem with words anyway.

I control-drag a UILabel from storyboard to corresponding implementation file to make the IBOutlet @property. Then I see two connections displayed when clicking the filled circle in the left side of the editor where shows line numbers. I don't know how to delete it.

Moreover, I see only ONE connection in storyboard's connections inspector of the UIlabel.

More weird, when I try to set the UILabel's text inside the setter of a public preperty, it fails to update the label's text:

 -(void) setQuestion:(NSString *)question
 {
     _question = question;
     self.questionLabel.text = question;
     NSLog(@"The quesion is %@",question);
     NSLog(@"The quesion label text is %@",self.questionLabel.text);
 }

I use two NSLog to debug and get the following. It shows the NSString *question is @"What do you want your label to say?", yet the self.questionLabel.text is null. The value assign fails. I suspect this relate to the duplicated connections thing mentioned above.

2012-07-29 04:03:53.817 Kitchen Sink[18628:f803] The quesion is What do you want your label to say?
2012-07-29 04:03:53.820 Kitchen Sink[18628:f803] The quesion label text is (null)

The following is the screenshot showing the duplicated connections. I am probably missing something obvious, please help.


回答1:


I would stalk this up to Xcode storyboard wonkiness.

First, try a clean of the project and a re-build.

Should you still have that problem, manually define the @property without dragging from the AskerViewController view to the AskerViewController implementation (.m) file by doing the following.

Cut that IBOutlet @property line in the interface section of the implementation (.m) file for AskerViewController. Click the label in storyboard. Disconnect any binding that label to the AskerViewController. Clean the project. Then, paste back in the property, and control-drag from the label to the view controller orb at the bottom of the AskerViewController view in your storyboard file.



来源:https://stackoverflow.com/questions/11704316/xcode-4-3-duplicated-connections-of-an-iboutlet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!