Lefora Free Forum
Loading
1572 views

Problems with placing Custom NSViews into an NSScrollView

Page 1
1–11
rookie - member
5 posts

Hi All,

In my program I have an NSScrollView and an NSView with it's own controller.

I'm trying to get it to automatically add instances of the NSView upon a button being clicked. So far that works fine.

However I'm having trouble getting the placement right. I would like them to start at the top of the NSScrollView and each new one to be below the previous one. At the moment upon adding the first one, it gets put at the bottom of the NSScrollView, then subsequent ones will move the rest up, and place themselves at the bottom.

Does anyone know what I'm doing wrong? I can add my code if it'll help but it's quite messy at the moment (it's a major work in progress).

Many thanks

Spatula

?
288 posts

For sure reducing your code to the least that can explain the problem is very helpful in three ways.  First, it'll help you clarify your thoughts.  Secondly, I can pick up your code and move to the heart of the matter.  We then have common code with which to discuss the issue and the solution.

Please post the code and I promise to look at it for you after work this evening.  Please delete the build directory and zip the rest - it should be about 50k.

__________________
rookie - member
5 posts

Sorry for not getting back to you sooner. I've done as you suggested, plus ripped out quite a bit of code that's not valid to the problem to try to keep it simpler for you.

I hope it's all ok, and many thanks for any help.

Spatula

Attachment: Rabbit-Hole.zip (747.0KB)

?
288 posts

Thanks for doing this.  It's 07:24 here in California and I'm going off work.  I'll look at this when I get home this evening from (another tough day at) the office.

__________________
?
288 posts

Hi Spat

Gosh, this is interesting.  I lost a little effort pulling down and trying (unsuccessfully) to build MCPKit - however that's irrelevant to the task.  I commented off some includes and declarations and got your code to run.  Right - I understand exactly what you've asked.  How interesting.

I've had a great (but sadly wrong) guess.  I instantly thought "IsFlipped".  There's a method on NSView called "IsFlipped" and this has something to do with causing the view to have the coord 0,0 in the top,left instead of bottom,left of the window (or something like that).  So I subclassed your NSScrollView with MyScrollView and updated IB to use that class on the time sheet scroller thing.  Saved in IB, rebuilt in XCode and indeed IsFlipped is being called.  Great disappointment, that didn't fix it.

Here's the state of the project:  http://clanmills.com/files/RabbitHole.zip

I'm not sure which timezone you're in, however I think you can look at this while I'm asleep.  Maybe I've applied IsFlipped to the wrong window or something simple.  Let me know how you get on.  If you're still stuck, I'll take another look at this on Thursday evening.

__________________
rookie - member
5 posts

Thank you for your help,

Sorry about MCPKit, I thought I had removed all references of it from my project (I spent a lot of time getting it to work too).

I decided to just start this function from the beginning again, and I've got it working fine. I'm not quite sure what I've done differently this time, but I suspect that it wasn't helped with all my going back and forth in the code.

I'm in England, so currently GMT +1. Once again thank you for taking the time out to help me

Spatula

?
288 posts

Hi Spat

Thanks for the update.  I'm really pleased that you're now running.

I'd be very interested to see how you solved that - and I might even be motivated to create a tutorial (and acknowledge your contribution) based on what you've done.  (there are some cocoa tutorials on clanmills.com).  If you have time to share your solution, I'd be very pleased to see how you got that to work - and of course a tutorial might save others time in the future.  

Best Wishes to everybody in the UK (my sons and grandchildren live in Surrey).

__________________
rookie - member
5 posts

Hi Clanmills,

Here's a new update: What I thought was my fix, didn't fix the problem (it's a long story to do with having to resize the document view).
However after Googling a bit, I've worked out how to use the "isFlipped" method.

The basic idea is that you create a subclass of NSView with the method -(BOOL)isFlipped {return YES;}
Then rather than creating an NSView which will eventually have the DocumentView set to it, you create your subclass.

This now seems to be working fine, except I have to now get it to create my views in descending order rather than ascending, but that shouldn't be too bad.

?
288 posts

Yes, your description of isFlipped is exactly what I added to your code last night !  I'm glad you're moving and having success.

__________________
rookie - member
5 posts

I came across a nice solution to the problem of everything now being flipped here: http://www.timothyborrowdale.co.uk/programming/64/nsscrollview-top-left-pinning-and-isflipped/

basically you have your flipped custom view, and that contains a normal NSView with everything you want in it.

?
288 posts

Wonderful. That's great - thank you for sharing that with everybody.

__________________
Page 1
1–11

Locked Topic


You must be a member to post in this forum

Join Now!