ios - Mac development NSView added child controls do not display
phpcn_u1582
phpcn_u1582 2017-05-17 10:05:24
0
2
1366

Now I have written a Demo program under the Mac platform. The upper layer is programmed using a mixture of c and OC. The viewcontroller suffix has also been changed to .mm. The interface is directly dragged and dropped using the storyboard. Two custom NSViews have been added, as follows As shown in the picture:

When programming, I passed the two custom NSViews on the right through the interface, converted the pointers of the two nsviews into void types, and passed a layer of c-layer encapsulated modules in the middle. Finally, Pass it to the bottom layer, and force the two void type pointers back to the nsview* type again. Then addsubview on the two nsviews and add two nstextfields. During debugging, it is shown that the number of subviews is indeed 1, indicating that the addition was successful. On.
Create controls and add sub-control codes:

     _TextField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20) ];
     [_parentView addSubview:_TextField];

After that, I used the UI inheritance debugging tool that comes with xcode, and the display also successfully added two nstextfields to nsview, as shown below:

You can see that the two NSViews on the right have successfully added two NStextfeilds.
However, these two text boxes cannot be seen in the actual running interface. In fact, they have become transparent and can be clicked. The runtime effect is like this:

My question is: Why does addsubview succeed but cannot display the sub-controls normally during runtime? The two controls become transparent. I have not made any settings related to transparency or background.
Is it related to the use of c OC mixed compilation? NSVIew also passes through a layer of c encapsulation when it is passed down?
I hope experienced friends can give me some advice, I would be very grateful, thank you!

phpcn_u1582
phpcn_u1582

reply all(2)
滿天的星座

Can you post the code that creates NSTextField和添加到view?
I tried dragging it directly into the graphical interface or adding code to display it.

淡淡烟草味

After searching for a day, I finally found the cause of the problem: the UI controls were not operated in the main thread, that is, the parent View addsubview was performed in the child thread.
Attachment 1: http://blog.csdn.net/msss00/a... Summary of reasons why iOS addsubview is not displayed)
Attachment 2: http://blog.csdn.net/libaineu... (iOS Two methods for child threads to update UI)
The problem is solved, also thanks to @tomdfriwel for his help.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template