有人可以幫我理解爲什麼insertobject atindex:0行不能添加任何東西到nsmutablearray中嗎?謝謝。nsmutablearray insertobject atindex:0不工作
- (void)setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
if (_splitViewBarButtonItem != splitViewBarButtonItem) {
NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
if (splitViewBarButtonItem) {
[toolbarItems insertObject:splitViewBarButtonItem atIndex:0];
NSLog(@"setSplitViewBarButtonItem: toolbarItems has %u objects",toolbarItems.count);
}
self.toolbar.items = toolbarItems;
_splitViewBarButtonItem = splitViewBarButtonItem;
}
}
工具欄早些時候在同一.m文件中定義從而
@property (nonatomic, weak) UIToolbar *toolbar;
我也試圖與
NSMutableArray *toolbarItems = [[NSMutableArray alloc]init];
toolbarItems = [self.toolbar.items mutableCopy];
更換線
NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
私有財產但仍然沒有什麼是adde d到toolbarItems。調試器始終顯示splitViewBarButtonItem爲非null,並且我的NSLog保持打印爲零。
非常感謝。