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 Dialog Popup and Optional Item - UIAlertView (Objective-C,iPhone)

iOS/iPhone Dialog Popup and Optional Item - UIAlertView (Objective-C,iPhone,iPad) บทความนี้จะเป็นการเขียนโปรแกรมบน iOS เพื่อแสดง Dialog Popup ด้วย UIAlertView โดยใน Popup จะแสดงรายการให้เลือก ซึ่งประกอบด้วยหลาย Optional Item และการแสดงรายการ Item ที่ได้เลือกไว้

iOS/iPhone Dialog Popup and Optional  Item

Dialog Popup and Optional Item


ในการสร้าง Item Optional สามารถสร้างง่าย ๆ ด้วย Class ของ UIAlertView โดยการเพิ่มที่ Property ของ otherButtonTitles เช่น otherButtonTitles:@"Item1",@"Item1",.... ตามตัวอย่าง

    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Please Select Item!"
                          message:@"This is" delegate:self
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:@"Item1",@"Item1",@"Item3",@"Item4", nil];
    [alert show];

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

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 1){
        lblResult.text = @"Your selected Item1";
    }else if(buttonIndex == 2)
    {
        lblResult.text = @"Your selected Item2";
    }else if(buttonIndex == 3)
    {
        lblResult.text = @"Your selected Item3";
    }else if(buttonIndex == 4)
    {
        lblResult.text = @"Your selected Item4";
    }
}


ทดสอบจริงบน Xcode กับ iPhone

iOS/iPhone Dialog Popup and Optional  Item

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

iOS/iPhone Dialog Popup and Optional  Item

กำหนดชื่อ Project และเลือกรายการดังรูป

iOS/iPhone Dialog Popup and Optional  Item

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








สำหรับ Code ของ .h และ .m

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)btnAlertView:(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)btnAlertView:(id)sender {
    
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Please Select Item!"
                          message:@"This is" delegate:self
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:@"Item1",@"Item1",@"Item3",@"Item4", nil];
    [alert show];
    
}

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 1){
        lblResult.text = @"Your selected Item1";
    }else if(buttonIndex == 2)
    {
        lblResult.text = @"Your selected Item2";
    }else if(buttonIndex == 3)
    {
        lblResult.text = @"Your selected Item3";
    }else if(buttonIndex == 4)
    {
        lblResult.text = @"Your selected Item4";
    }
}

@end


Screenshot

iOS/iPhone Dialog Popup and Optional  Item

คลิกที่ Popup เพื่อเปิด Dialog

iOS/iPhone Dialog Popup and Optional  Item

แสดงรายการ Dialog ซึ่งจะมีให้เลือกหลาย Item

iOS/iPhone Dialog Popup and Optional  Item

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








   
Share


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


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


   


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

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

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

 
iOS/iPhone Textbox in Popup - UITextField / 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 05
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 อัตราราคา คลิกที่นี่