Skip to content

A few UIKit components that use blocks instead of target/actions or delegates.

License

Notifications You must be signed in to change notification settings

Bunch/UIKit-Block-Based-Components

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIKit Block-based components

A few UIKit components that use blocks instead of target/actions or delegates. The following components are included:

  • UIActionSheet
  • UIAlertView
  • UIBarButtonItem

Usage

You can see the sample project in the Demo folder.

OCActionSheet

Instantiate an action sheet with the following:

+ (id)actionSheetWithTitle:(NSString *)title;

Then use any of these methods to add buttons to the action sheet:

- (void)addButtonWithTitle:(NSString *)title 
					action:(void (^)(void))actionBlock;

- (void)addCancelButtonWithTitle:(NSString *)title 
						  action:(void (^)(void))actionBlock;

- (void)addDestructiveButtonWithTitle:(NSString *)title 
							   action:(void (^)(void))actionBlock;

Show it the usual way.

OCAlertView

The easier way is to instantiate an alert view with the following:

+ (id)alertViewWithTitle:(NSString *)title
			 message:(NSString*)message
		 cancelTitle:(NSString *)cancelTitle
		cancelAction:(void(^)(void))cancelBlock
		confirmTitle:(NSString *)confirmTitle
	   confirmAction:(void(^)(void))confirmBlock;

You could use this method to add a button to an alert view that requires more than 2 buttons:

- (void)addButtonWithTitle:(NSString *)title action:(void (^)(void))actionBlock;

Show it the usual way.

OCBarButtonItem

Instantiate a button with any of the following constructors:

+ (id)itemWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem 
					  actionBlock:(void (^)(void))actionBlock;

+ (id)itemWithCustomView:(UIView *)customView 
			 actionBlock:(void (^)(void))actionBlock;

+ (id)itemWithImage:(UIImage *)image 
			  style:(UIBarButtonItemStyle)style
		actionBlock:(void (^)(void))actionBlock;

+ (id)itemWithImage:(UIImage *)image 
landscapeImagePhone:(UIImage *)landscapeImagePhone 
			  style:(UIBarButtonItemStyle)style
	    actionBlock:(void (^)(void))actionBlock;

+ (id)itemWithTitle:(NSString *)title 
			  style:(UIBarButtonItemStyle)style 
		actionBlock:(void (^)(void))actionBlock;

You could use this method to set a block to a bar button item (not recommended though):

- (void)setActionBlock:(void (^)(void))actionBlock;

WARNING: Do not set the target and action after you set an action block, the action block won't be called otherwise.

Important

The code is taking advantage of Automatic Reference Counting (ARC). If your project does not use ARC, you will need to update the code. If you do so, please do it nicely, fork the project and send a pull request.

About

A few UIKit components that use blocks instead of target/actions or delegates.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 100.0%