Skip to content

Instantly share code, notes, and snippets.

@davidmurray
Created October 27, 2014 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmurray/71885bd167979309d10f to your computer and use it in GitHub Desktop.
Save davidmurray/71885bd167979309d10f to your computer and use it in GitHub Desktop.
Find the first icon list view with an empty spot
static SBIconListView *MTGetFirstAvailableIconListView()
{
SBRootFolderController *rootFolderController = [[%c(SBIconController) sharedInstance] _rootFolderController];
SBRootFolderView *rootFolderView = [rootFolderController contentView];
// Attempt to find a model that has an available spot.
for (SBIconListView *view in [rootFolderView iconListViews]) {
if (![[view model] isFull]) {
return view;
}
}
// We couldn't find any available icon list views, therefore we will add a new one.
SBRootFolder *rootFolder = [rootFolderController folder];
SBIconListModel *emptyModel = [rootFolder addEmptyList];
if (!emptyModel) {
return nil;
}
SBIconListView *iconListView = [rootFolderView iconListViewAtIndex:[rootFolder indexOfList:emptyModel]];
return iconListView;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment