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 voidtypes, and passed a layer of c-layer encapsulated modules in the middle. Finally, Pass it to the bottom layer, and force the two voidtype 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!
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.