0

我实现了一个方法,每次运行该方法时都会在索引处添加一个工具栏项。

thetoolbar.insertItemWithItemIdentifier("safaributton", atIndex: 3)

我必须用 if/else 包装这个插入工具栏项的代码,否则当方法运行时,我会将此项重复添加到工具栏。

if ?????? {
    // execute only if the toolbar item with identifier does not already exist.
    thetoolbar.insertItemWithItemIdentifier("safaributton", atIndex: 3)
}

我找不到合适的方法来检查索引 3 处当前工具栏项的标识符..?

4

1 回答 1

0

.itemIdentifier as opposed to .identifier

if thetoolbar.items[3].itemIdentifier != "safaributton"{
        thetoolbar.insertItemWithItemIdentifier("safaributton", atIndex: 3)
    }
于 2015-01-30T16:42:03.363 回答