• This repository has been archived on 28/Aug/2018
  • Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 14 years ago
  • Updated about 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple UIAlertView wrapper that uses blocks for button actions.

λ-alert

This repo contains two simple wrappers around UIAlertView and UIActionSheet that allow you to use blocks for actions, so that you don’t have to mess with delegate callbacks and button indexes. Please note that since iOS 8 you should use the official UIAlertController instead.

Installing

This project includes a podspec for usage with CocoaPods. Simply add

pod 'Lambda-Alert'

to your Podfile and run pod install.

Alternately, you can add all of the files contained in this project's Library directory to your Xcode project. If your project does not use ARC, you will need to enable ARC on these files. You can enable ARC per-file by adding the -fobjc-arc flag, as described on a common StackOverflow question.

Finally, you could clone the whole repository and drag the project to an Xcode workspace. Then you can add libLambdaAlert to the list of linked libraries for your target and start using the code.

Usage

Displaying an alert:

CCAlertView *alert = [[CCAlertView alloc]
    initWithTitle:@"Test Alert"
    message:@"See if the thing works."];
[alert addButtonWithTitle:@"Foo" block:^{ NSLog(@"Foo"); }];
[alert addButtonWithTitle:@"Bar" block:^{ NSLog(@"Bar"); }];
[alert addButtonWithTitle:@"Cancel" block:NULL];
[alert show];

Displaying a sheet:

CCActionSheet *sheet = [[CCActionSheet alloc] initWithTitle:@"Action Sheet"];
[sheet addButtonWithTitle:@"Miles" block:^{ NSLog(@"Trumpet"); }];
[sheet addButtonWithTitle:@"Trane" block:^{ NSLog(@"Saxophone"); }];
[sheet addDestructiveButtonWithTitle:@"Monk" block:^{ NSLog(@"Piano"); }];
[sheet addCancelButtonWithTitle:@"Back to the Head"];
[sheet showInView:window];

The alert will keep itself from being deallocated until closed.

Extra features

  • Both classes feature a dismissAction block that will be called when the dialog is dismissed, be it with a button tap, cancelling or dismissing through the -dismissAnimated: method.
  • Both classes have a -dismissAnimated: method that will dismiss the dialog without pressing any of the buttons. This method does not perform the cancel button action, but it does call the dismissAction block mentioned in the previous bullet.
  • You can also dismiss the dialog by posting a notification to the standard notification center. The name of the notification is documented in the header files. If you want the dismissal to be animated, include a userInfo dictionary with the notification that returns an appropriate NSNumber instance for CCActionSheetAnimatedKey or CCAlertViewAnimatedKey. The notification triggers -dismissAnimated:, so the notes above apply.

Links

Author & License

Licensed under the terms of the MIT License:

Copyright © Tomáš Znamenáček, [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

The software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the Software or the use or other dealings in the Software.

More Repositories

1

Finch

Simple, low-latency OpenAL sound engine for Apple iOS.
Objective-C
436
star
2

UILabel-Clipboard-Sample

Sample project demonstrating how you can display the pasteboard menu on an UILabel.
Objective-C
41
star
3

TestingUserDefaults

Simple NSUserDefaults replacement for testing purposes.
Objective-C
20
star
4

ios-keyboards

An overview of the layouts and sizes used by the system keyboard in iOS.
Swift
13
star
5

Singletons-Suck

Sample Xcode project showing how to wire an app without singletons
Objective-C
8
star
6

Factory

Experimental dependency injection container for Objective-C.
Objective-C
8
star
7

Movies

A sample Swift iOS client for themoviedb.org
Swift
3
star
8

Google-Suggest-Objective-C

An Objective-C library for reading Google Suggest results
Objective-C
3
star
9

mastodon-cz

Průvodce českým Mastodonem
Ruby
3
star
10

typed-forms

An experimental typed form library for iOS
Swift
2
star
11

MessageRecorder

Sample code showing how to record and replay messages in Objective-C.
Objective-C
2
star
12

ios-url-scheme-length-limit

A sample app testing how much data can be transferred through a custom URL scheme
Swift
2
star
13

Conference-Timer

Simple big-letter iPad timer suitable for conference talks.
Objective-C
2
star
14

CloudKitUserDiscovery

A sample Swift project showing user discovery through CloudKit.
Swift
1
star
15

Naboso

Web divadla NABOSO
HTML
1
star
16

vim-lastline

Jump to the last line being edited when returning to a file in Vim
Vim Script
1
star
17

URLShortener

A goo.gl URL shortener client written in Swift
Swift
1
star
18

TZTableMenu

A UITableView data source and delegate well suited to creating table menus
Objective-C
1
star
19

Teclo-Sampler

Simple, live performance oriented sampler for iOS.
Objective-C
1
star