Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Commit

Permalink
Fixed issue with popover controller in iPad
Browse files Browse the repository at this point in the history
Changed the SegmentedControl on the keyboard accessory to buttons.
Buttons are necessary to anchor the Pop-over controller in iPad
Closes #23, closes #45
  • Loading branch information
raykrash authored and ginatrapani committed Oct 29, 2011
1 parent e2dc452 commit d5fc6aa
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 99 deletions.
1 change: 1 addition & 0 deletions Classes/ActionSheetPicker.h
Expand Up @@ -13,6 +13,7 @@

#import <Foundation/Foundation.h>
#import "MBProgressHUD.h"
#import "todo_txt_touch_iosAppDelegate.h"


@interface ActionSheetPicker : NSObject <UIPickerViewDelegate, UIPickerViewDataSource, MBProgressHUDDelegate> {
Expand Down
9 changes: 7 additions & 2 deletions Classes/ActionSheetPicker.m
Expand Up @@ -54,7 +54,7 @@ + (void)showHUDWithCustomView:(UIView *)view withMessage:(NSString *)message {

// The sample image is based on the work by http://www.pixelpressicons.com, http://creativecommons.org/licenses/by/2.5/ca/
// Make the customViews 37 by 37 pixels for best results (those are the bounds of the build-in progress indicators)
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]] autorelease];
HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"alert_white.png"]] autorelease];

// Set custom view mode
HUD.mode = MBProgressHUDModeCustomView;
Expand Down Expand Up @@ -167,7 +167,12 @@ - (void)showActionPicker {
viewController.view = view;
viewController.contentSizeForViewInPopover = viewController.view.frame.size;
_popOverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
[self.popOverController presentPopoverFromRect:self.view.frame inView:self.view.superview?:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

//The clicked button is saved into the appdelegate. The Popover is anchored to that.
todo_txt_touch_iosAppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
[self.popOverController presentPopoverFromBarButtonItem:appdelegate.lastClickedButton
permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

} else {
//spawn actionsheet
_actionSheet = [[UIActionSheet alloc] initWithTitle:[self isViewPortrait]?nil:@"\n\n\n" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
Expand Down
1 change: 1 addition & 0 deletions Classes/TaskEditViewController.h
Expand Up @@ -79,6 +79,7 @@
- (IBAction)doneButtonPressed:(id)sender;
- (IBAction)helpButtonPressed:(id)sender;
- (IBAction)segmentControlPressed:(id)sender;
- (IBAction) keyboardAccessoryButtonPressed:(id)sender;
- (void) addEditTask;

@end
55 changes: 30 additions & 25 deletions Classes/TaskEditViewController.m
Expand Up @@ -259,38 +259,43 @@ - (void) contextWasSelected:(NSNumber *)selectedIndex:(id)element {
[textView becomeFirstResponder];
}

- (IBAction)segmentControlPressed:(id)sender {
[textView resignFirstResponder];

id<TaskBag> taskBag = [todo_txt_touch_iosAppDelegate sharedTaskBag];
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
- (IBAction) keyboardAccessoryButtonPressed:(id)sender {

switch (segmentedControl.selectedSegmentIndex) {
case 0: // Priority
[ActionSheetPicker displayActionPickerWithView:self.view
data:[Priority allCodes]
selectedIndex:0
target:self
action:@selector(priorityWasSelected::)
title:@"Select Priority"];
break;
case 1: // Project
[ActionSheetPicker displayActionPickerWithView:self.view
data:[taskBag projects]
selectedIndex:0
target:self
action:@selector(projectWasSelected::)
title:@"Select Project"];
break;
case 2: // Context
id<TaskBag> taskBag = [todo_txt_touch_iosAppDelegate sharedTaskBag];

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//For ipad, we have ample space and it is not necessary to hide the keyboard
todo_txt_touch_iosAppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
appdelegate.lastClickedButton = sender;
} else {
[textView resignFirstResponder];
}

UIBarButtonItem *button = (UIBarButtonItem*)sender;

if([button.title isEqualToString:@"Context"]) { // Context
[ActionSheetPicker displayActionPickerWithView:self.view
data:[taskBag contexts]
selectedIndex:0
target:self
action:@selector(contextWasSelected::)
title:@"Select Context"];
break;
}
} else if([button.title isEqualToString:@"Priority"]) { // Priority
[ActionSheetPicker displayActionPickerWithView:self.view
data:[Priority allCodes]
selectedIndex:0
target:self
action:@selector(priorityWasSelected::)
title:@"Select Priority"];

} else if([button.title isEqualToString:@"Project"]) { // Priority
[ActionSheetPicker displayActionPickerWithView:self.view
data:[taskBag projects]
selectedIndex:0
target:self
action:@selector(projectWasSelected::)
title:@"Select Project"];
}
}


Expand Down
2 changes: 2 additions & 0 deletions Classes/todo_txt_touch_iosAppDelegate.h
Expand Up @@ -62,13 +62,15 @@
UINavigationController *navigationController;
id <TaskBag> taskBag;
RemoteClientManager *remoteClientManager;
id lastClickedButton; //Anchor holder for the Popover in iPad
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet todo_txt_touch_iosViewController *viewController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, readonly) id <TaskBag> taskBag;
@property (nonatomic, readonly) RemoteClientManager *remoteClientManager;
@property (nonatomic, retain) id lastClickedButton;

- (void) syncClient;
- (void) syncClientForceChoice:(BOOL)forceChoice;
Expand Down
1 change: 1 addition & 0 deletions Classes/todo_txt_touch_iosAppDelegate.m
Expand Up @@ -64,6 +64,7 @@ @implementation todo_txt_touch_iosAppDelegate
@synthesize navigationController;
@synthesize taskBag;
@synthesize remoteClientManager;
@synthesize lastClickedButton;


#pragma mark -
Expand Down
137 changes: 65 additions & 72 deletions TaskEditAccessoryView.xib
Expand Up @@ -12,10 +12,9 @@
</object>
<object class="NSArray" key="IBDocument.IntegratedClassDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>IBUIBarButtonItem</string>
<string>IBUIToolbar</string>
<string>IBUISegmentedControl</string>
<string>IBProxyObject</string>
<string>IBUIToolbar</string>
<string>IBUIBarButtonItem</string>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -41,64 +40,31 @@
<object class="IBUIToolbar" id="868484999">
<reference key="NSNextResponder"/>
<int key="NSvFlags">266</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUISegmentedControl" id="140320910">
<reference key="NSNextResponder" ref="868484999"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{6, 8}, {197, 30}}</string>
<reference key="NSSuperview" ref="868484999"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBSegmentControlStyle">2</int>
<int key="IBNumberOfSegments">3</int>
<object class="NSArray" key="IBSegmentTitles">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>Priority</string>
<string>Project</string>
<string>Context</string>
</object>
<object class="NSMutableArray" key="IBSegmentWidths">
<bool key="EncodedWithXMLCoder">YES</bool>
<real value="0.0"/>
<real value="0.0"/>
<real value="0.0"/>
</object>
<object class="NSMutableArray" key="IBSegmentEnabledStates">
<bool key="EncodedWithXMLCoder">YES</bool>
<boolean value="YES"/>
<boolean value="YES"/>
<boolean value="YES"/>
</object>
<object class="NSMutableArray" key="IBSegmentContentOffsets">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>{0, 0}</string>
<string>{0, 0}</string>
<string>{0, 0}</string>
</object>
<object class="NSMutableArray" key="IBSegmentImages">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSNull" id="4"/>
<reference ref="4"/>
<reference ref="4"/>
</object>
<bool key="IBMomentary">YES</bool>
</object>
</object>
<string key="NSFrameSize">{320, 44}</string>
<reference key="NSSuperview"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="140320910"/>
<reference key="NSNextKeyView"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClearsContextBeforeDrawing">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableArray" key="IBUIItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIBarButtonItem" id="649094238">
<object class="IBUIBarButtonItem" id="1033068989">
<string key="IBUITitle">Priority</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<reference key="IBUICustomView" ref="140320910"/>
<int key="IBUIStyle">1</int>
<reference key="IBUIToolbar" ref="868484999"/>
</object>
<object class="IBUIBarButtonItem" id="586474127">
<string key="IBUITitle">Project</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIStyle">1</int>
<reference key="IBUIToolbar" ref="868484999"/>
</object>
<object class="IBUIBarButtonItem" id="331730287">
<string key="IBUITitle">Context</string>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIStyle">1</int>
<reference key="IBUIToolbar" ref="868484999"/>
</object>
<object class="IBUIBarButtonItem" id="310620680">
Expand Down Expand Up @@ -136,12 +102,27 @@
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">segmentControlPressed:</string>
<reference key="source" ref="140320910"/>
<string key="label">keyboardAccessoryButtonPressed:</string>
<reference key="source" ref="331730287"/>
<reference key="destination" ref="841351856"/>
<int key="IBEventType">13</int>
</object>
<int key="connectionID">12</int>
<int key="connectionID">14</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">keyboardAccessoryButtonPressed:</string>
<reference key="source" ref="1033068989"/>
<reference key="destination" ref="841351856"/>
</object>
<int key="connectionID">17</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchEventConnection" key="connection">
<string key="label">keyboardAccessoryButtonPressed:</string>
<reference key="source" ref="586474127"/>
<reference key="destination" ref="841351856"/>
</object>
<int key="connectionID">18</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
Expand Down Expand Up @@ -170,8 +151,10 @@
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="664041669"/>
<reference ref="649094238"/>
<reference ref="310620680"/>
<reference ref="331730287"/>
<reference ref="586474127"/>
<reference ref="1033068989"/>
</object>
<reference key="parent" ref="0"/>
</object>
Expand All @@ -181,22 +164,23 @@
<reference key="parent" ref="868484999"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">8</int>
<reference key="object" ref="649094238"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="140320910"/>
</object>
<int key="objectID">10</int>
<reference key="object" ref="310620680"/>
<reference key="parent" ref="868484999"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">7</int>
<reference key="object" ref="140320910"/>
<reference key="parent" ref="649094238"/>
<int key="objectID">13</int>
<reference key="object" ref="331730287"/>
<reference key="parent" ref="868484999"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">10</int>
<reference key="object" ref="310620680"/>
<int key="objectID">15</int>
<reference key="object" ref="586474127"/>
<reference key="parent" ref="868484999"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">16</int>
<reference key="object" ref="1033068989"/>
<reference key="parent" ref="868484999"/>
</object>
</object>
Expand All @@ -208,10 +192,11 @@
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
<string>10.IBPluginDependency</string>
<string>13.IBPluginDependency</string>
<string>15.IBPluginDependency</string>
<string>16.IBPluginDependency</string>
<string>4.IBPluginDependency</string>
<string>5.IBPluginDependency</string>
<string>7.IBPluginDependency</string>
<string>7.IUISegmentedControlInspectorSelectedSegmentMetadataKey</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand All @@ -221,7 +206,8 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<integer value="1"/>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
Expand All @@ -236,7 +222,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">12</int>
<int key="maxID">18</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -251,6 +237,7 @@
<string>cancelButtonPressed:</string>
<string>doneButtonPressed:</string>
<string>helpButtonPressed:</string>
<string>keyboardAccessoryButtonPressed:</string>
<string>segmentControlPressed:</string>
</object>
<object class="NSMutableArray" key="dict.values">
Expand All @@ -259,6 +246,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
Expand All @@ -268,6 +256,7 @@
<string>cancelButtonPressed:</string>
<string>doneButtonPressed:</string>
<string>helpButtonPressed:</string>
<string>keyboardAccessoryButtonPressed:</string>
<string>segmentControlPressed:</string>
</object>
<object class="NSMutableArray" key="dict.values">
Expand All @@ -284,6 +273,10 @@
<string key="name">helpButtonPressed:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">keyboardAccessoryButtonPressed:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">segmentControlPressed:</string>
<string key="candidateClassName">id</string>
Expand Down
Binary file added alert_white.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d5fc6aa

Please sign in to comment.