Permalink
Browse files

Add popoved-strategy. remove leaks

  • Loading branch information...
1 parent d93c1d2 commit 64375b6efec6d0bd6586a94c812613c755cb04fc @Malaar committed Sep 8, 2012
View
@@ -438,12 +438,16 @@ - (BOOL)validate
{
validatableObject.validatableText = [validatableObject.validatableText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- NSRegularExpression* regExp = [[NSRegularExpression alloc]initWithPattern:@"^(http://|https://|[a-zA-Z0-9])(([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}$"
- options:NSRegularExpressionCaseInsensitive error:nil];
-
NSUInteger count = 0;
if(validatableObject && validatableObject.validatableText)
- count = [regExp numberOfMatchesInString:validatableObject.validatableText options:0 range:NSMakeRange(0, [validatableObject.validatableText length])];
+ {
+ NSRegularExpression* regExp = [[NSRegularExpression alloc]initWithPattern:@"^(http://|https://|[a-zA-Z0-9])(([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,6}$"
+ options:NSRegularExpressionCaseInsensitive error:nil];
+ count = [regExp numberOfMatchesInString:validatableObject.validatableText
+ options:0
+ range:NSMakeRange(0, [validatableObject.validatableText length])];
+ [regExp release];
+ }
return count == 1;
}
View
@@ -17,5 +17,6 @@
#import "MUControllers.h"
#import "MUTableDisposers.h"
#import "MUDraw.h"
+#import "MUStrategy.h"
#endif
@@ -0,0 +1,28 @@
+//
+// MUPopovedStrategy.h
+// MUKit
+//
+// Created by Malaar on 06.06.12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "MUPopoverable.h"
+
+@interface MUPopovedStrategy : NSObject
+
+@property (nonatomic, assign) Class popoverBackgroundViewClass;
+
+@property (nonatomic, retain, readonly) UIView* popovedView;
+@property (nonatomic, retain, readonly) UIPopoverController *popoverController;
+@property (nonatomic, assign, readonly) UIPopoverArrowDirection permittedArrowDirections;
+
+
+- (void) presentPopoverFromView:(UIView*)aView
+ withContentController:(UIViewController<MUPopoverable>*)aPopoverableController
+ permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
+ animated:(BOOL)animated;
+
+- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
+
+@end
@@ -0,0 +1,84 @@
+//
+// MUPopovedStrategy.m
+// MUKit
+//
+// Created by Malaar on 06.06.12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import "MUPopovedStrategy.h"
+
+
+@interface MUPopovedStrategy ()
+
+- (UIPopoverController*) popoverControllerWithContent:(UIViewController*)aController;
+
+@end
+
+@implementation MUPopovedStrategy
+
+@synthesize popoverBackgroundViewClass;
+@synthesize popovedView;
+@synthesize popoverController;
+@synthesize permittedArrowDirections;
+
+//==============================================================================
+- (void) dealloc
+{
+ [popovedView release];
+ [popoverController release];
+
+ [super dealloc];
+}
+
+//==============================================================================
+- (void) presentPopoverFromView:(UIView*)aView
+ withContentController:(UIViewController<MUPopoverable>*)aPopoverableController
+ permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
+ animated:(BOOL)animated
+{
+ popovedView = [aView retain];
+ permittedArrowDirections = arrowDirections;
+ popoverController = [[self popoverControllerWithContent:aPopoverableController] retain];
+ aPopoverableController.popover = self.popoverController;
+
+ [self.popoverController presentPopoverFromRect:popovedView.bounds
+ inView:popovedView
+ permittedArrowDirections:permittedArrowDirections
+ animated:animated];
+}
+
+//==============================================================================
+- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
+{
+ if(popoverController.isPopoverVisible)
+ {
+ [popoverController dismissPopoverAnimated:NO];
+
+ [popoverController presentPopoverFromRect:popovedView.bounds
+ inView:popovedView
+ permittedArrowDirections:permittedArrowDirections
+ animated:NO];
+ }
+}
+
+#pragma mark - Private
+//==============================================================================
+- (UIPopoverController*) popoverControllerWithContent:(UIViewController*)aController
+{
+ if(!popoverController)
+ {
+ popoverController = [[[UIPopoverController alloc] initWithContentViewController:aController] autorelease];
+ if(popoverBackgroundViewClass)
+ [popoverController setPopoverBackgroundViewClass:popoverBackgroundViewClass];
+ }
+ else
+ {
+ [popoverController setContentViewController:aController];
+ [popoverController setPopoverContentSize:aController.contentSizeForViewInPopover];
+ }
+
+ return popoverController;
+}
+
+@end
@@ -0,0 +1,16 @@
+//
+// MDPopovable.h
+// MUKit
+//
+// Created by Malaar on 07.06.12.
+// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@protocol MUPopoverable <NSObject>
+
+@property (nonatomic, assign) UIPopoverController* popover;
+
+@end
+
@@ -0,0 +1,14 @@
+//
+// MUStrategy.h
+// MUKitTest
+//
+// Created by Malaar on 08.09.12.
+//
+//
+
+#ifndef MUKitTest_Strategy_h
+#define MUKitTest_Strategy_h
+
+#import "MUStrategy.h"
+
+#endif
@@ -53,6 +53,7 @@
025A62C5152F17FD00E49856 /* MUToolbar.m in Sources */ = {isa = PBXBuildFile; fileRef = 025A6297152F17FD00E49856 /* MUToolbar.m */; };
0263608815F3BFCE00B655A1 /* MUCoreDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0263608715F3BFCE00B655A1 /* MUCoreDataManager.m */; };
0263608B15F3BFF600B655A1 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0263608A15F3BFF600B655A1 /* CoreData.framework */; };
+ 027F8E6515FB888F00201DD4 /* MUPopovedStrategy.m in Sources */ = {isa = PBXBuildFile; fileRef = 027F8E6215FB888F00201DD4 /* MUPopovedStrategy.m */; };
028693EA152C55C70040FD86 /* MUCellDataTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 028693E9152C55C70040FD86 /* MUCellDataTextView.m */; };
028693EE152C568B0040FD86 /* MUCellDataTextPair.m in Sources */ = {isa = PBXBuildFile; fileRef = 028693ED152C568B0040FD86 /* MUCellDataTextPair.m */; };
028693F1152C63250040FD86 /* MUCellTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = 028693F0152C63250040FD86 /* MUCellTextView.m */; };
@@ -213,6 +214,10 @@
0263608615F3BFCE00B655A1 /* MUCoreDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUCoreDataManager.h; sourceTree = "<group>"; };
0263608715F3BFCE00B655A1 /* MUCoreDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MUCoreDataManager.m; sourceTree = "<group>"; };
0263608A15F3BFF600B655A1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
+ 027F8E6115FB888F00201DD4 /* MUPopovedStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUPopovedStrategy.h; sourceTree = "<group>"; };
+ 027F8E6215FB888F00201DD4 /* MUPopovedStrategy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MUPopovedStrategy.m; sourceTree = "<group>"; };
+ 027F8E6315FB888F00201DD4 /* MUPopoverable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUPopoverable.h; sourceTree = "<group>"; };
+ 027F8E6415FB888F00201DD4 /* MUStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUStrategy.h; sourceTree = "<group>"; };
028693E8152C55C70040FD86 /* MUCellDataTextView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUCellDataTextView.h; sourceTree = "<group>"; };
028693E9152C55C70040FD86 /* MUCellDataTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MUCellDataTextView.m; sourceTree = "<group>"; };
028693EC152C568B0040FD86 /* MUCellDataTextPair.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MUCellDataTextPair.h; sourceTree = "<group>"; };
@@ -556,6 +561,25 @@
path = MUCoreData;
sourceTree = "<group>";
};
+ 027F8E5F15FB888F00201DD4 /* MUStrategy */ = {
+ isa = PBXGroup;
+ children = (
+ 027F8E6415FB888F00201DD4 /* MUStrategy.h */,
+ 027F8E6015FB888F00201DD4 /* MUPopoved */,
+ );
+ path = MUStrategy;
+ sourceTree = "<group>";
+ };
+ 027F8E6015FB888F00201DD4 /* MUPopoved */ = {
+ isa = PBXGroup;
+ children = (
+ 027F8E6115FB888F00201DD4 /* MUPopovedStrategy.h */,
+ 027F8E6215FB888F00201DD4 /* MUPopovedStrategy.m */,
+ 027F8E6315FB888F00201DD4 /* MUPopoverable.h */,
+ );
+ path = MUPopoved;
+ sourceTree = "<group>";
+ };
028F8D2515259B3600C7907F /* MUTableDisposer */ = {
isa = PBXGroup;
children = (
@@ -757,6 +781,7 @@
isa = PBXGroup;
children = (
02A20965152D07030010733B /* MUKit.h */,
+ 027F8E5F15FB888F00201DD4 /* MUStrategy */,
0263608515F3BFCE00B655A1 /* MUCoreData */,
02A01D5915A71ABE007AEE1B /* MUDraw */,
025A6232152F17FC00E49856 /* MUControllers */,
@@ -1086,6 +1111,7 @@
02EFC344155C1D7C00E2639C /* TableViewWithMapedCells.m in Sources */,
02A01D5C15A71ABE007AEE1B /* MUDraw.m in Sources */,
0263608815F3BFCE00B655A1 /* MUCoreDataManager.m in Sources */,
+ 027F8E6515FB888F00201DD4 /* MUPopovedStrategy.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -97,10 +97,10 @@ - (void)viewDidLoad
cellDataTextField.placeholder = @"please enter text";
[section addCellData: cellDataTextField];
- MUTestObject* testObject = [MUTestObject new];
+ MUTestObject* testObject = [[MUTestObject new] autorelease];
testObject.strValue = @"string value";
- MUCellDataTextView* cdTextView = [[MUCellDataTextView alloc] initWithObject:testObject key:@"strValue"];
+ MUCellDataTextView* cdTextView = [[[MUCellDataTextView alloc] initWithObject:testObject key:@"strValue"] autorelease];
cdTextView.title = @"Title";
// cdTextView.enableEdit = NO;
[section addCellData:cdTextView];

0 comments on commit 64375b6

Please sign in to comment.