Adding a toolbar
The next step is to tie my word list display to the ability to add words. I'm going to create a toolbar and have an 'add words' button on the toolbar. I'm planning to reserve the area at the top for a 'delete button'. This seems in common with the Mail paradigm, so I want to act like other apps.
Step 1: Refactoring my UISelection to allow toggling selection on and off
I plan to migrate my UISelectionMaster to be a 'general purpose' dialog that can display items and invoke actions. This means that I need to be able to turn selection on and off as well as display toolbar items. I'm refactoring it so that there are now routines to turn selection on and off:
I added a readonly property and two messages to start and stop selection. I could have overridden the 'set/get' properties of this, but feel that having a message is a more explicit method of control than setting properties with side effects.
- (void) startSelection;
- (void) stopSelection;
- (bool) isInSelectionMode;
- (void) startSelection
{
if (!isInSelectionMode)
{
self.selectionController=[[JLSelectionController alloc] init];
[selectionController addToContainer:listToSelect];
isInSelectionMode=true;
}
}
- (void) stopSelection{
if (isInSelectionMode)
{
[selectionController removeFromContainer:listToSelect];
isInSelectionMode=false;
self.selectionController=nil;
}
}
Step 2: Adding the ability to create a simple toolbar.
Just to test the functionality I created a method that will display a toolbar with a single button. This is certainly not an optimal way to do it. Note that I allow the target to be passed in, this keeps my control separate from my display.
- (void) showToolbar:(NSString *) buttonName target:(id) target action:(SEL) action;
- (void) showToolbar:(NSString *) buttonName target:(id) target action:(SEL) action
{
[self.navigationController setToolbarHidden:false];
UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithTitle:buttonName style:UIBarButtonItemStyleBordered target:target action:action];
NSArray *items = [NSArray arrayWithObjects: item, nil];
self.navigationController.toolbar.items =items;
[item release];
}
Step 3:Invoking the toolbar.
Finally I modified my edit words so that it displays the dialog with the toolbar, and has a callback that invokes the next dialog in the sequence when the item is chosen. Then it has additional callbacks to handle adding words from that dialog.
- (IBAction) editList:(id) sender
{
JLTableContainer *container=
[JLTableContainer createSetController:nil forList:currentWordList.containedWords
sortKey:@"wordName" inContext:[SightWordState Instance].control.managedObjectContext
controlledBy:nil];
UISelectionMaster * selector=[[UISelectionMaster alloc] init];
selector.listToSelect=container;
[self.navigationController pushViewController:selector animated:true];
[selector showToolbar:@"Add Words" target:self action:@selector(AddWords:)];
}
- (IBAction) AddWords:(id) sender
{
SelectSuggestedItems *selectItems=[[SelectSuggestedItems alloc] init];
selectItems.coreControl=[SightWordState Instance].control;
selectItems.managedTable=@"WordInformation";
selectItems.searchVariable=@"wordName";
selectItems.delegate=self;
[self.navigationController pushViewController:selectItems animated:YES];
[selectItems release];
}
The reason I'm keeping the control at the higher level is that I can isolate my business logic into a class that is separate from my display logic. Right now I have everything glommed into one class, I plan to refractor this into a set of smaller helper classes in the future.
Bugs:
This is a rather incomplete API. When you go to a subview the toolbar stays displayed, but blank, and when you return to the previous item, the toolbar is still blank.
In addition I need to refractor the code so that I can have nicer toolbars than a single button.
The goal of the framework is to have feature rich hierarchy and list management without having to create .NIB files for toolbars and the like. In addition I want to be able to control the display and behavior easily. By doing this I can concentrate my GUI design on a smaller set of GUIs, but the basic editing is contained in a set of helper classes. All of this behavior is VERY similar no matter what your problem domain is, I want to avoid cutting & pasting the same code for behavior everywhere:
Deleting items
Selecting items
Adding items
No comments:
Post a Comment