ios – UIDocumentBrowserViewController – appended trailing navigation bar merchandise is all the time first

0
14
ios – UIDocumentBrowserViewController – appended trailing navigation bar merchandise is all the time first


I am utilizing UIDocumentBrowserViewController. There are already two trailing navigation bar button gadgets created by this view. I don’t reference them in my code nor do I decide their actions. I need to add a 3rd button, and have it positioned farthest to the trailing aspect.

If my button is represented by C, then the order from left-to-right or leading-to-trailing needs to be A B C.

I am trying so as to add it utilizing additionaltrailingnavigationbarbuttonitems:

class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate
{
    override func viewDidLoad()
    {
        tremendous.viewDidLoad()

        let button = UIBarButtonItem(...)
        
        additionalTrailingNavigationBarButtonItems.append(button)
    }
}

This all the time provides it because the leftmost trailing merchandise. The order when the view masses is C A B, the place C represents my button.

Listed here are some issues I’ve tried:

  • Add it in viewWillAppear – identical outcomes.
  • Add it in viewDidAppear – identical outcomes.
  • Add it utilizing rightBarButtonItems – doesn’t present up in any respect.
  • insert it at: 0 as an alternative of appending it – identical outcomes.
  • Add it with a delay utilizing DispatchQueue.primary.async – identical outcomes.

I experimented with the delay on the DispatchQueue to see if possibly I used to be appending it too early within the course of, when the opposite two had not but been added. Even when utilizing a 5 second delay, my button would nonetheless be on the leftmost aspect after being appended. On this case, I noticed the view load with the 2 default buttons, after which 5 seconds later my button was appended and appeared on the leftmost aspect.

So I added one other examine for the size of additionalTrailingNavigationBarButtonItems instantly earlier than appending my button, and it’s all the time zero. This explains why irrespective of how I add my button to it, my button all the time seems on the leftmost aspect – as a result of there’s nothing else in that array.

One other strategy to verify that is to aim to insert(at: 1) even after a 5 second delay. Visually the opposite two buttons are there, however this may trigger an index-out-of-range error and crash the app.

How do I put my button farther to the trailing/proper aspect of those two default buttons?

LEAVE A REPLY

Please enter your comment!
Please enter your name here