How to copy class interface and implementation without connections to .xib file

  • (You may reply in Caps Lock if this question is too noobish for this list)

    I wrote an experimental project for Mac OS X. It uses a custom NSView and some user interface controls connected to the view's class in Interface Builder.

    I want to do about the same project for iOS, so I started a new project in Xcode 4.3.3 and created a new class which will be a custom UIView. I copied most of the code from the Mac OS X version into the interface and implementation of the new class in the new project. Unfortunately the connections with the .xib from the other project are still there, which is obviously not what I want. I just want to connect the IBOutlets and IBActions to the .xib in my new iOS project.

    What did I do wrong? And how did all those books I read not make me smart enough to figure this out on my own? I must be getting old...

    [[[Brainchild alloc] initWithName:@"Richard Altenburg"] saysBestRegards];
  • On Jul 1, 2012, at 1:39 PM, Richard Altenburg (Brainchild) wrote:

    > Unfortunately the connections with the .xib from the other project are still there, which is obviously not what I want.

    I’m not sure I understand what you mean by this. Did you copy over the .xib from the other project? If so, of course it will contain all the connections from the old .xib, since it’s the same .xib. Just set up a new .xib file, or modify the old one to remove everything that doesn’t need to be there.

    Charles
  • Thanks for your thoughts, Charles.

    No, I did not copy the .xib to a new project.

    I created a new project for iOS wit one view, and created a new class in it that is to be a subclass of UIView which will contain my drawing code in drawRect. I copied code from the old project over into the new project, into the .h and .m files of the new class. It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project. I connected them to my new .xib in my new project, but how on earth are old ones copied over to a new project is beyond me at this moment.

    [[[Brainchild alloc] initWithName:@"Richard Altenburg"] saysBestRegards];

    Op 1 jul. 2012, om 21:21 heeft Charles Srstka het volgende geschreven:

    > ’m not sure I understand what you mean by this. Did you copy over the .xib from the other project? If so, of course it will contain all the connections from the old .xib, since it’s the same .xib. Just set up a new .xib file, or modify the old one to remove everything that doesn’t need to be there.
  • On Jul 1, 2012, at 1:54 PM, Richard Altenburg (Brainchild) wrote:

    > It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project.

    Um, what _exactly_ did it show? There's no way for files in different projects to have relations to each other like that.

    —Jens
  • On Jul 1, 2012, at 4:54 PM, Richard Altenburg (Brainchild) wrote:
    > Thanks for your thoughts, Charles.
    >
    > No, I did not copy the .xib to a new project.
    >
    > I created a new project for iOS wit one view, and created a new class in it that is to be a subclass of UIView which will contain my drawing code in drawRect. I copied code from the old project over into the new project, into the .h and .m files of the new class. It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project. I connected them to my new .xib in my new project, but how on earth are old ones copied over to a new project is beyond me at this moment.

    At least once I've started a new project and within the new window a file was open that belonged to a previously opened project. I wonder if this is what happened to you, and the xib file you were looking at was not the xib file in your new project.

    If you Command-click the file icon in the window's title bar, you can see the full path of the file you are looking at. If the path goes to the old project, close it with File > Close "YourFileName.xib". The keyboard equivalent is Control-Command-W. You might even want to close *all* files that are open in that window by holding down that key until the window says "No Editor". Closing the project window and reopening might help -- I didn't think to try that.

    Then click on the xib as listed on the left, in the file navigator pane. *That* xib, the correct one, shouldn't have any mysterious connections. The only connected outlets should be any that are automatically created when you create certain kinds of nib, e.g., from a window controller to a window.

    --Andy
  • Op 1 jul. 2012, om 22:59 heeft Jens Alfke het volgende geschreven:

    >> It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project.
    >
    > Um, what _exactly_ did it show? There's no way for files in different projects to have relations to each other like that.

    When you declare a property as an IBOutlet, you get that 'open bullet' left to it showing you a connection to a user interface element can be made. After I copied code from the old projects' .h file into my new projects' .h file, there was a 'closed bullet', and when I connected this property to the new .xib file, there was still the connection with the old .xib file, which of course was in the old project.

    Testing the interface made Xcode hang, so it was not happy with that external connection itself, but I was not able to remove it at that time.
  • Op 2 jul. 2012, om 00:57 heeft Andy Lee het volgende geschreven:

    > If you Command-click the file icon in the window's title bar, you can see the full path of the file you are looking at. If the path goes to the old project, close it with File > Close "YourFileName.xib". The keyboard equivalent is Control-Command-W. You might even want to close *all* files that are open in that window by holding down that key until the window says "No Editor". Closing the project window and reopening might help -- I didn't think to try that.

    I could not figure out the problem yesterday. I have seen it before, by the way, but as I was really just starting with some basic code back then I did not bother at all. I could just rewrite the few lines I had. That is not what I want to do now, there is too much code to type this time, so I copied it over from the old project.

    When I clicked on the 'closed bullet' (the filled in circle left of an IBOutlet or IBAction in my .h and .m files) I got a popup with not one but two connections in it. One was to a UI element in my new projects' .xib file, but the other, when clicked, clearly brought my old project to the front, and as I removed the connections to that old project, what I really did was modifying the old .xib which I confirmed by compiling my old project and running it: the UI did not work anymore, the connections were gone.

    I ended up renaming the IBOutlets and IBActions in my new project which helped me get rid of the old connections. From here I can go on to actually make this new little app running, I guess.

    Sorry if this all sounds silly, but it has been an unexpected time pit for me (and you guys), and I hope to one day understand what happened. Thank you all for your help. I hope to have questions in the future that are more interesting than this weird one...

    Best,

    Richard.
  • On Jul 2, 2012, at 1:01 AM, Richard Altenburg (Brainchild) wrote:

    > Op 1 jul. 2012, om 22:59 heeft Jens Alfke het volgende geschreven:
    >
    >>> It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project.
    >>
    >> Um, what _exactly_ did it show? There's no way for files in different projects to have relations to each other like that.
    >
    > When you declare a property as an IBOutlet, you get that 'open bullet' left to it showing you a connection to a user interface element can be made. After I copied code from the old projects' .h file into my new projects' .h file, there was a 'closed bullet', and when I connected this property to the new .xib file, there was still the connection with the old .xib file, which of course was in the old project.
    >
    > Testing the interface made Xcode hang, so it was not happy with that external connection itself, but I was not able to remove it at that time.

    All the connections are in the .xib file itself, not in the source files. If the .xib file isn’t part of your project, this really shouldn’t be possible. And it *definitely* shouldn’t be able to affect anything at runtime, because the only way your nib should be able to be loaded is if you either load it yourself with either -[NSNib initWithNibNamed:bundle:] or by giving the nib name to NSDocument, NSWindowController, NSViewController, etc. And that shouldn’t be possible to happen if the nib isn’t being included inside the app bundle unless you’re explicitly specifying a URL to it in code.

    I guess what I’m saying is, check over your project and make sure you don’t accidentally have some reference to the .xib file (or the project containing it) in your project anywhere.

    Charles
  • Thank you for elaborating on this, Charles. I was able to remove any connections to the old project by inserting new IBOutlets and IBActions with new names and pasting the code from the old project into the definition of the new methods. Copying the complete declarations copied over the connections to the old projects' .xib as well, so I won't do that again to avoid this problem.

    [[[Brainchild alloc] initWithName:@"Richard Altenburg"] saysBestRegards];

    Op 2 jul. 2012, om 09:41 heeft Charles Srstka het volgende geschreven:

    > I guess what I’m saying is, check over your project and make sure you don’t accidentally have some reference to the .xib file (or the project containing it) in your project anywhere.
  • On Jul 1, 2012, at 11:01 PM, "Richard Altenburg (Brainchild)" <cocoa-dev...> wrote:

    > Op 1 jul. 2012, om 22:59 heeft Jens Alfke het volgende geschreven:
    >
    >>> It immediately showed that the outlets and actions were connected, and on inspection they were connected to the .xib in the old project.
    >>
    >> Um, what _exactly_ did it show? There's no way for files in different projects to have relations to each other like that.
    >
    > When you declare a property as an IBOutlet, you get that 'open bullet' left to it showing you a connection to a user interface element can be made. After I copied code from the old projects' .h file into my new projects' .h file, there was a 'closed bullet', and when I connected this property to the new .xib file, there was still the connection with the old .xib file, which of course was in the old project.

    This sounds like an Xcode indexing bug. If you can reproduce it, please file a bug at http://bugreport.apple.com.

    >
    > Testing the interface made Xcode hang, so it was not happy with that external connection itself, but I was not able to remove it at that time.

    As I'm sure we all know, there are a thousand and one reasons Xcode 4 might hang. Best to take a sample using sample(1) or sysdiagnose(1) and file a bug report when that happens.

    --Kyle Sluder
previous month july 2012 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today