Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

robvas

macrumors 68040
Original poster
Mar 29, 2009
3,240
631
USA
I'm experimenting with making an IRC program. If you're not familiar with IRC, you can be multiple channels at once. In the client, you can switch channels (chat rooms) and the chat log as well as the nick list (the list of other people in the channel) will reflect what is in your current channel.

I decided to put each channel in it's own tab view. Then as an exercise, I made the tabview tabless, and put some nsbuttons at the top of the window so you can switch between channels.

I made the nick list on the right side of the screen scrollable, since some channels have hundreds of participants. I made a mockup of the user interface, and you can enter the name of a channel and click the + button, and it will 'create' that channel. It adds a button for the tab, a textview for the chat, and an scrollview with a tableview inside for the nick list.

Here's my problem. I create a channel when the program begins. It appears fine. But when I add a new channel, it doesn't work! I can switch back to the first channel, and it appears right.

This is what the first tab looks like, and what I want the others to look like:
iBdYJ.png


Code:
        [[newTab view] addSubview:newChannel.nickScrollView];
        [[newTab view] addSubview:newChannel.nickList];
Produces this:
AGLGf.png


Code:
        [newChannel.nickScrollView setDocumentView:newChannel.nickList];
        [[newTab view] addSubview:newChannel.nickScrollView];
Produces this:
zVIH0.png


If I change the code so that I just add the scrollview and the tableview to the tabview, they both show up. But if I change it to put the table inside the scroll view, it shows up but doesn't draw any columns or data. My datasource methods never get called. I colored the scrollview blue and the tableview gray for debugging purposes.

I'm sure it's something very simple. I have some memory leaks in my code (and probably other issues) but I'm just worried about the scrollview issue for now. My project is attached and if anyone took a look I would appreciate it.
 

Attachments

  • Channels.zip
    55.3 KB · Views: 109
I believe when you create a tableview it is already embedded in a scroll view, so you may be doing more than you need to here.
 
I believe when you create a tableview it is already embedded in a scroll view, so you may be doing more than you need to here.

I will research the tableview more, the way my code is I don't have any settings for scroll properties on the table view.

I noticed if I added more names to the list, the list shows in the other channels, but only the last couple ones. And I can't scroll up to see the rest.
 
NsTableView is a subclass of NSView, which defines the method -enclosingScrollView. You could use that method to see if there is a scroll view attached to the table and thence adjust the settings (e.g., autohiding of the scroller). If you log the value and it returns nil, then I would be mistaken.

One way to make this all simple would be to create channel.nib, layout your stuff in a view object, and set FilesOwner to your IRCChannelController object you design, then you can just load nibs for channels, the controller object handling the placement of its view object. One advantage to this is that each channel controller could implement features like notification or automatic tab switching on activity.
 
I figured it out. The tableview kept growing to all kinds of weird sizes when I added it to the tab.

[newChannel.nickScrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];

That was the cuplrit. Ugh!

One way to make this all simple would be to create channel.nib, layout your stuff in a view object, and set FilesOwner to your IRCChannelController object you design, then you can just load nibs for channels, the controller object handling the placement of its view object. One advantage to this is that each channel controller could implement features like notification or automatic tab switching on activity.

I'm not sure what I'm going to use for the UI on this program yet - I will probably do at least a test/sample project using nibs for that type of window layout.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.