Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone



Clound SSD Virtual Server

iOS/iPhone Confirm Dialog Popup - UIAlertView (Objective-C,iPhone,iPad)

iOS/iPhone Confirm Dialog Popup - UIAlertView (Objective-C,iPhone,iPad) บทความนี้เราจะมารู้วิธีการเขียน iOS แสดงผลบน iPhone และการทำปุ่ม Confirm Popup Dialog เพื่อรอให้ผู้ใช้ทำการยืนยันข้อมูลต่าง ๆ บนหน้าจอ และการอ่าน Event ที่ได้จากผู้ใช้

iOS/iPhone Confirm Dialog Popup

Confirm Dialog Popup


ในการสร้าง Confirm Alert Dialog บน iOS จะใช้ Class ที่มีชื่อว่า UIAlertView ได้แบบง่าย ๆ โดยเราสามารถสร้าง Popup และการรับค่าจากผู้ใช้ที่ได้เลือกไว้ ตามตัวอย่างนี้

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Confirm!"
                          message:@"Do you want to Cancel?"
                          delegate: self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"OK", nil];
    [alert show];
    [alert release];

การรับค่าสามารถใช้คำสั่ง

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if(buttonIndex == 0)
    {
        lblResult.text = @" Your selected Cancel.";
    }else if(buttonIndex == 1)
    {
        lblResult.text = @" Your selected OK."; 
    }
    
}


มาดูตัวอย่างจริงบน Xcode และ iPhone

iOS/iPhone Confirm Dialog Popup

สร้าง Project ง่าย ๆ ด้วย Single View Application

iOS/iPhone Confirm Dialog Popup

กำหนดชื่อ Project โดยไม่เลือก Storyboard

iOS/iPhone Confirm Dialog Popup

ออกแบบหน้าจอด้วย Interface Builder ดังรูป แล้วทำการเชื่อม IBOutlet และ IBAction ให้เรียบร้อย ด้วย








ส่วน Code ต่าง ตามนี้

ViewController.h
//
//  ViewController.h
//
//  Created by Weerachai on 10/27/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
    IBOutlet UILabel *lblResult;
}


- (IBAction)btnConfirm:(id)sender;

@end

ViewController.m
//
//  ViewController.m
//
//  Created by Weerachai on 10/27/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [lblResult release];
    [super dealloc];
}

- (IBAction)btnConfirm:(id)sender {
    
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Confirm!"
                          message:@"Do you want to Cancel?"
                          delegate: self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"OK", nil];
    [alert show];
    [alert release];
    
}


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if(buttonIndex == 0)
    {
        lblResult.text = @" Your selected Cancel.";
    }else if(buttonIndex == 1)
    {
        lblResult.text = @" Your selected OK."; 
    }
    
}

@end


Screenshot

iOS/iPhone Confirm Dialog Popup

แสดงหน้าจอบน iPhone ทดสอบคลิกที่ Button เพื่อเปิด Popup

iOS/iPhone Confirm Dialog Popup

แสดง Popup แบบ Confirm Dialog

iOS/iPhone Confirm Dialog Popup

แสดงรายการที่เลือก







.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-10-29 15:13:46 / 2017-03-25 22:44:31
  Download : Download  iOS/iPhone Confirm Dialog Popup - UIAlertView (Objective-C,iPhone,iPad)
 Sponsored Links / Related

 
การสร้าง Message Box หรือ Alert ด้วย UIAlertView บน iOS (iPhone,iPad)
Rating :

 
iOS/iPhone Textbox in Popup - UITextField / UIAlertView (Objective-C,iPhone)
Rating :

 
iOS/iPhone Dialog Popup and Optional Item - UIAlertView (Objective-C,iPhone)
Rating :

 
iOS/iPhone Username and Password Popup - UIAlertView (Objective-C,iPhone)
Rating :

 
iOS/iPhone Action Sheet Popup - UIActionSheet (Objective-C,iPhone,iPad)
Rating :

 
iOS/iPhone Adding Show Image Action Sheet (UIActionSheet) and Alert View (UIAlertView)
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่