Tech-Today
XCode: Create A Simple AlertView
Open Xcode and create a new Single View Application. For product name, use SimpleAlertView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices.
Drag a button inside the view controller and change its title to "Show AlertView".
We will need to connect the button to the view controller. Select the assistant editor and open the ViewController.m file. Ctrl and drag from the label to the class section and create the following action.
Inside the ViewController.m, change the line
@interface ViewController ()
to
@interface ViewController () <UIAlertViewDelegate>
Inside the method of btn_showAlertView that we have created, insert this lines of code
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"OK Dialog"
message:@"This is OK dialog"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles: nil];
[alert addButtonWithTitle:@"Cancel"];
[alert show];
To handle which button is clicked, insert this method
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
NSLog(@"You have clicked Ok");
}
else if(buttonIndex == 1)
{
NSLog(@"You have clicked Cancel");
}
}
Build and Run the project, an alert view should appear when the "Show AlertView" button is clicked.
You can download the source code of the SimpleAlertView at my repository on bitbucket.
-
How To Display An Alert View With Swift
Display an Alert View with Swift First we'll create a constant of UIAlertController. Since we'll be using an alert, the UIAlertControllerStyle is set to default. It can have other values such as ActionSheet, Alert, and RawValue. let alertPrompt...
-
How To Implement Local Notification In Swift
The following steps will guide us on how to develop an application in Swift that implements Local Notification. Requirements are:MacXcode6 - BetaXiOS8StepsOpen xcode.Create a Single View Application, let's name it LocalNotification.Register for user...
-
Create A Simple Table View App In Xcode
Open Xcode and create a new Single View Application. For product name, use SimpleTableView and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. Drag a table view inside the view controller....
-
How To Differentiate Between 3.5 And 4 Inch Iphone
Open Xcode and create a new Single View Application. For product name, use DifferentiateIphoneSize and then fill out the Organization Name and Company Identifier with your customary values. Select iPhone for Devices. For demonstration purposes, add a...
-
Webview Tutorial In Ios 8 With Swift
The UIWebView class is use to embed web content in an application. It can be done by simply creating a UIWebView object and attaching it to a window and then sending it a request to load web content. Open Xcode and create a new Single View Application....
Tech-Today