Xcode9 crashes when adding multiple bar button items to toolbar

Version:


Xcode 9a235


When I drag a toolbar into my view, and then try to add multiple bar button items into the toolbar, if I change one of the bar button items from System Item to "Reply", "Action" or any of those icons, the page hangs forever and I get stuck at a spinning wheel.


Please help!

Is it OSX or IOS (I guess so) ?

Did it work in XCode 8 ?


When you change one of the bar button items from System Item to "Reply",

what do you change exactly ?

Hi there,


It is OSX (Sierra v10.12.6)


Basically if I have more than 1 button in the toolbar, and I try to change any one of the buttons' icon from the default text "Item", to "reply" (a little back arrow), or "trash" (a trashcan), my computer just hangs.

lilybeans,


Have you found any solution to this? I just ran across this... same Xcode build but with High Sierra.

I have the same problem here. Have never used XCode before so don't have anything to compare it to. Running V9.0. Toolbar works fine if I don't change button types in toolbar, but if I change one to Reply, for example, XCode locks up.

Toolbars are buggy in xcode 9.0. Change flexible space item to fixed or visa versa and xcode exits. Also you can't change the width of UIButton in a toolbar. This all worked in 8.3.3.

This is really frustrating. I submitted a bug report to Apple and got a response that they found no crash. I've tried Xcode 9 on different computers, and even the latest 9.1 beta that was posted yesterday, and all have the same issue.

do you get some crash report ?

Ive got the same issue.

Whenever i choose any bar button and change the system item, it just hangs, with fixed or flexible space.


Im using xcode 9 and Sierra v10.12.6


This IS very annoying...

Same problem here. Was working fine in xcode 8.


Tried with xcode 9 and 9.1 on Sierra 10.12 and High Sierra.


Hope Apple is working on this. As of now xcode 9 is useless.

Same problem here. I'm a new user taking a Udemy course and cannot go any farther in the course until this problem is resolved. For others that reported this problem, what was the actual response back from Apple? I'm using High Sierra 10.13 and Xcode 9.0 ((A235).


Thanks in advance.

Same problem here.Has anyone tried to implement the toolbar/button item programmatically? I'm trying to figure it out as a workaround so I can complete a tutorial. Post code here please.

if you want a work around here is the way to implement the code programatically. note line 25 deomonstrates how to implement a "play" button

override func viewDidLoad() {
        super.viewDidLoad()
       
       
        /
        self.view.backgroundColor = UIColor.black
       
        /
       let myToolbar = UIToolbar(frame: (CGRect(x: 0, y: self.view.bounds.size.height - 44, width: self.view.bounds.size.width, height: 40)))
        /
        myToolbar.layer.position = CGPoint(x: self.view.bounds.width/2, y: self.view.bounds.height-20.0)
       
        /
        myToolbar.barStyle = .blackTranslucent
        myToolbar.tintColor = UIColor.white
        myToolbar.backgroundColor = UIColor.black
       
        /
        let myUIBarButtonGreen: UIBarButtonItem = UIBarButtonItem(title: "Green", style:.plain, target: self, action: #selector(onClickBarButton(sender:)))
        myUIBarButtonGreen.tag = 1
       
        let myUIBarButtonBlue: UIBarButtonItem = UIBarButtonItem(title: "Blue", style:.plain, target: self, action: #selector(onClickBarButton(sender:)))
        myUIBarButtonBlue.tag = 2
       
        let myUIBarButtonRed: UIBarButtonItem = UIBarButtonItem(title: "Red", style: .plain, target: self, action: #selector(onClickBarButton(sender:)))
        myUIBarButtonRed.tag = 3
       
        let myUIBarButtonItemPlay: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .play, target: self, action: #selector(onClickBarButton(sender:)))
        myUIBarButtonItemPlay.tag = 4
        /
        myToolbar.items = [myUIBarButtonGreen, myUIBarButtonBlue, myUIBarButtonRed, myUIBarButtonItemPlay]
       
        /
        self.view.addSubview(myToolbar)
    }
   
    @objc func onClickBarButton(sender: UIBarButtonItem) {
       
        switch sender.tag {
        case 1:
            self.view.backgroundColor = UIColor.green
        case 2:
            self.view.backgroundColor = UIColor.blue
        case 3:
            self.view.backgroundColor = UIColor.red
        case 4:
            self.view.backgroundColor = UIColor.white
        default:
            print("ERROR!!")
        }
    }

Wierd. I just tried to get the same error for 'fun' and it happed to me ONCE! Changed button to trash, clicked outside, and it froze! Had to force quit it. Reopened and it went back to before the trash icon. Tried it again, and NO ISSUES!

Your actions didn't work for me. I'm using xcode Version 9.0.1 (9A1004). what version are you using?

Also do you have more that one button item? Try with more that one, if you have not.

Were you able to solve this problem? I am experiencing the same thing right now. I set the tool bar at the bottom of the app, i then insert a bar button item and it crashes.

Was using current version. I'm upgrading to xcode 9.1 as I type this. I'll let you know what happens.

same problem here..soo annoying....

Have you solved the problem? I am now having the same problem.

Same problem here. Ugh!

Same problem. Setting "View as" to iPhone SE also freezes Xcode 9.1. Xcode has amazing features, but has been consistently unreliable since Swift. I wonder if Xcode is tested at Apple before release.

Annoying that our apps must go through a review process but Apple will happily push out their own buggy software!


I threw together this hacky script that will transform all the button bar items in a storyboard to change the icons to 'cancel'. It records the original button bar items to a file you provide. This means you can now edit the storyboard file in the ui. Except all the button bar items will be cancel icons. To restore these run the script again and the original button bar icons will be restored.


We keep all our storyboard items in one huge storyboard file so this script was not created with multiple storyboards in mind! Use at own risk 😀



import os
import termcolor


# your storyboard file here!
currentStoryboardFilename = YOUR ORIGINAL STORYBOARD FILE HERE


originalStoryboardWithMetadataFileName = A FILE NAME FOR STORING THE ORIGINAL BUTTON BAR ITEMS


# temp file that gets deleted after script is run
transformedStoryboardFileName = "transformedStoryboard" 


barButtonItem = "barButtonItem"
systemItem = "systemItem"
systemItemWithEqualsAndQuote = systemItem + "=\""
requiredItems = [barButtonItem, systemItem]


cancel = "cancel"
flexibleSpace = "flexibleSpace"
fixedSpace = "fixedSpace"
systemItemIsCancel = "systemItem=\"cancel\""
idString = "id=\""
skipItems = [flexibleSpace, fixedSpace, systemItemIsCancel]


metadataHeader = "###metadata#"


def getOriginalBarButtons(storyboardWithMetadata):
isInMetadataSection = False
idList = []
# get list of (id, original line) tuples
for line in storyboardWithMetadata:
if isInMetadataSection:
idIndex = line.find(idString) + len(idString)
endQuoteIndex = line.find("\"", idIndex)
idValue = line[idIndex:endQuoteIndex]
idList.append((idValue, line))
if metadataHeader in line:
isInMetadataSection = True
return idList


def isLineABarButtonItem(line):
return all(item in line for item in requiredItems)


def isLineABarButtonToSkip(line):
return any(item in line for item in skipItems)


def getOriginalBarButtonItem(line, idList):
for idTuple in idList:
if idTuple[0] in line:
return idTuple[1]
# else
return line


def transformBarButtonToCancelIcon(line):
indexOfSystemItemValue = line.find(systemItemWithEqualsAndQuote)
indexOfSystemItemValue += len(systemItemWithEqualsAndQuote)
indexOfLastQuoteAroundSystemItemValue = line.find("\"", indexOfSystemItemValue)
firstPart = line[:indexOfSystemItemValue]
secondPart = line[indexOfLastQuoteAroundSystemItemValue:]


return firstPart + cancel + secondPart




def makeStoryboardSourceOnlyEditable():
currentStoryboardFile = open(currentStoryboardFilename, 'r')
originalStoryboardWithMetadata = open(originalStoryboardWithMetadataFileName, 'r')
transformedFile = open(transformedStoryboardFileName, 'w')

idList = getOriginalBarButtons(originalStoryboardWithMetadata)

for line in currentStoryboardFile:
if isLineABarButtonItem(line):
line = getOriginalBarButtonItem(line, idList)
transformedFile.write(line)


originalStoryboardWithMetadata.close()
currentStoryboardFile.close()
transformedFile.close()


os.remove(originalStoryboardWithMetadataFileName)
os.rename(transformedStoryboardFileName, currentStoryboardFilename)
termcolor.cprint("Transformed storyboard to source editing only mode", "green")



def makeStoryboardUIEditable():
# we don't have a copy of the original storyboard file so make a copy
originalStoryboardWithMetadata = open(originalStoryboardWithMetadataFileName, 'w')
currentStoryboardFile = open(currentStoryboardFilename, 'r')
transformedStoryboard = open(transformedStoryboardFileName, 'w')


originalItemsFooter = metadataHeader + "\n"
for line in currentStoryboardFile:
originalStoryboardWithMetadata.write(line)


# if line is a bar button item and has a systemItem then record original line at the top of the file as a comment
if isLineABarButtonItem(line) and not isLineABarButtonToSkip(line):
safeToOpenUILine = transformBarButtonToCancelIcon(line)
transformedStoryboard.write(safeToOpenUILine)
originalItemsFooter += "%s" % line
else:
transformedStoryboard.write(line)


originalStoryboardWithMetadata.write(originalItemsFooter)
originalStoryboardWithMetadata.close()
currentStoryboardFile.close()
transformedStoryboard.close()


os.rename(transformedStoryboardFileName, currentStoryboardFilename)
termcolor.cprint("Transformed storyboard to ui safe mode", "green")


if os.path.isfile(originalStoryboardWithMetadataFileName):
makeStoryboardSourceOnlyEditable()
else:
makeStoryboardUIEditable()

Same thing happens to me ! Simply cannot change the System Item of a Bar Button Item, placed in a ToolBar at the button, from Custom to <something else> when there is another Bar Button Item in the same ToolBar. Either I am not allowed to do this or this is a bug

I found a fix guys!!!! But I don't know how to explain it

Can you tell the fix? The Bug allready exists and i can not found any solution. 😟

Xcode9 crashes when adding multiple bar button items to toolbar
 
 
Q