📜 ⬆️ ⬇️

Funny tabs on MAC OS X or a story about that Tab View

Hello to all!

The story began with the fact that I needed to write an application under Mac OS X. More and more rarely, you can see articles about the development for the desktop, and even under Mac OS X, but this topic is about that.

I already wrote a lot of things on QT, and then the challenge was to use exclusively Cocoa.
')
There is a certain aura of holiness around apple products, well, I naively fell under it from my MacBook. It seemed to me that there would be no special problems with the user interface, well, except perhaps some minor things that are everywhere (oh, how wrong I was).

Here in the project I reached the development of the user interface and here I needed the classic Tab View template. Continued read already under the cut.



Prehistory


In general, the most common project in terms of user interface. The user clicks the connect button, enters the data to log in to the server, presses OK, and a tab for this server appears, and so on. You can login to many servers and they will be in different tabs. What kind of server and why is it all needed? This is another subject area not related to this article, so I can tell you this information another time.

Naive developer


Under Mac OS X, and even under iOS, I have never developed it, this is my first experience, maybe that is what made me even more naive.
I thought that everything is easier than ever, I’ll throw in the Tab View constructor or whatever it will be called in Cocoa in the window, I’ll set up the display and that's it, but it wasn’t there.

I find in the Xcode tab view, throw in the window and see this


Here I already had suspicions that some difficulties might arise.

Okay, I thought, I started looking for other widgets for tabs, they are not there. Well, I decided to understand the settings of this Tab View. 10 minutes fiddling with the settings and realizing that Tab View to the tab view in the same Safari / Finder / Xcode and others, it does not lead, I went in search of the limitless expanses of the Internet.

During the first few views of posts on http://stackoverflow.com it became clear that Tab View is not at all what I need, I'm not alone.

Search for an alternative solution


Then there was such a moment in the development when not a single line of code was being written, but a lot of text was being read and a lot of coffee was being drunk.
At the beginning, I tried to find something from Apple themselves, but it quickly became clear that it was useless.
Then I went to various forums where this problem and ways to solve it were discussed. Pretty quickly, I already found several options for adding tabs to applications on Mac OS X.



The first two options were the most common and with a lot of functionality, and I decided to deal with them.
PSMTabBarControl is a well- developed project with good functionality, but has not been supported for a long time. By the way, it is used in Adium.
MMTabBarView is essentially a continuation and development of PSMTabBarControl, but in spite of this, its support is no better.
If you look at his page on github , then he has 44 fork, and all this because the developer has not committed anything to the master branch for a year, although he did some improvements in develop (but this appears to be very few people notice).
44 fork and among them are a few active ones leaving the last commit in master and claiming that they fixed some bugs.
Then I decided to take the one that is more actively supported by others.

One of the forks was chosen (as it turned out later it doesn’t matter which one).

In MMTabBarView there is a demo project that was compiled and worked without any problems:



Then I thought that everything was fine, the fork was alive and you could work with it.
I included the framework in the assembly of my project, made all the settings, wrote the necessary code, run it and nothing. Tabov no!

Dead end


Tabov is not, okay, I started to understand and found out that something similar to tabs appears if I do not update the Tab View



If for example add a tab then everything disappears.



Here the fun began. I began to try everything I could, first all reasonable means, and then not reasonable ones.


In general, the numerous experiments took more than one day.

At the end I had 2 projects, almost empty and completely identical. In one tabs work, and in the other not. Meeting with such inexplicable, our ancestors began to believe in the supernatural.

Thought began to emerge that you need to search for another library.

Eureka or rather luck


In the end, after a long search for an incomprehensible problem, I decided to find on github the simplest and smallest project using MMTabBarView and compare it with mine.
Some small browser was found. From it, I removed all unnecessary, and began to compare with your project. Everything was identical. He also worked with MMTabBarView assemblies from different forks without any problems.
Then an idea arose in this working project to make a new window and try to connect tabs in it.
And then the victory, the tabs did not work. And here I have one project, with one xib file, the tabs work with the other not.
The conclusion was obvious, it is necessary to compare these files.

It works here:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="13F1603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" promptedForUpgradeToXcode5="NO"> 


It does not work here:
 <?xml version="1.0" encoding="UTF-8" standalone="no"?> <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6751" systemVersion="13F1603" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> 


In the first tag I found the problem:
 customObjectInstantitationMethod="direct" 

If you remove this attribute then MMTabBarView starts to work correctly.

Apparently this is due to the fact that MMTabBarView is drawn just in CustomView and this attribute somehow affects it.

We start to understand what it is:

Google and Yandex provide a bunch of links to indexed xib files.

I found several references to this attribute related to other problems , but why he never figured it out. If someone knows what this attribute is and why it is needed, write it down, I will be very grateful.

Conclusion


MMTabBarView is a pretty good project, it supports a different tab display, a tab counter, adding icons, adding close buttons and adding a new tab, and much more. It is a pity that he smeared on a pile of forks and it is not clear at the moment how to put it together.
Apple, of course, upset me, how can this be, in all applications there is an element of the user interface, but it is not in the library !?
The funny thing is that tabs are in xcode :)

PS
Here is a small example of how to connect MMTabBarView to your project.

Useful links:
stackoverflow.com/questions/27354262/safari-style-tabs-cocoa-control?rq=1
stackoverflow.com/questions/2774668/does-anyone-know-a-safari-style-tab-control-for-mac-os-x-applications?rq=1
stackoverflow.com/questions/22789341/better-psmtabbarcontrol-cocoa-tabs
stackoverflow.com/questions/4986920/tabs-style-in-the-cocoa?rq=1

Source: https://habr.com/ru/post/278091/


All Articles