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 Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView) ในการสร้าง Activity Indicator View ซึ่งเป็น Icons หมุ่น ๆ แสดง Progress ในขณะทำงาน เราสามารถใช้งานได้ง่าย ๆ ด้วยการสร้างจาก Object ของ Interface Builder เพียงแค่ลากไปวางไว้ในหน้าจอ View ก็สามารถที่จะสร้างได้ทันที และนอกจากนี้เราสามารถที่จะ Apply ตัว Activity Indicator View (UIActivityIndicatorView) ให้แสดงผลบน Alert View (UIAlertView) หรือ Dialog Popup ได้เช่นเดียวกัน

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)


สำหรับ UIActivityIndicatorView บน UIAlertView อาจจะใช้ทำงานในขณะที่ App กำลังโหลดข้อมูล หรือทำงานที่ต้องใช้เวลา โดยที่เราไม่ทราบเวลาการทำงารที่แน่นอน แต่เพียงแจ้งให้ผู้ใช้ทราบว่าในขณะนี้กำลังทำงานอยู่เท่านั้น

การแสดง Progress บน Popup
    loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [loading addSubview:progress];
    [progress startAnimating];
    [progress release];
    [loading show];

การซ่อนหรือหยุดการทำงาน
    [loading dismissWithClickedButtonIndex:0 animated:YES];
    [loading release];


Example ตัวอย่างการสร้าง Activity Indicator View (UIActivityIndicatorView) บน Alert View (UIAlertView)

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

เริ่มต้นด้วยการสร้าง Application บน Xcode แบบ Single View Application แบบง่าย ๆ

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

เลือกและไม่เลือกรายการดังรูป

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

ตอนนี้หน้าจอ View จะยังว่าง ๆ

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

ทำการสร้าง Button บนหน้าจอ View และให้ Class ของ .h ให้ทำการเชื่อม IBAction









จากนั้นให้เขียน Code ดังนี้

ViewController.h
//
//  ViewController.h
//  UIAlertViewUIActivityIndicatorView
//
//  Created by Weerachai on 12/8/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


- (IBAction)btnOpenPopup:(id)sender;

@end


ViewController.m
//
//  ViewController.m
//  UIAlertViewUIActivityIndicatorView
//
//  Created by Weerachai on 12/8/55 BE.
//  Copyright (c) 2555 Weerachai. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UIAlertView *loading;
}

@end

@implementation ViewController

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

- (IBAction)btnOpenPopup:(id)sender {
    
    loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
    UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
    progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    [loading addSubview:progress];
    [progress startAnimating];
    [progress release];
    [loading show];
    
    // for Hide 
    //[loading dismissWithClickedButtonIndex:0 animated:YES];
    //[loading release];
}

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


@end


Screenshot

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

แสดงหน้าแรก ให้คลิกที่ Button เพื่อแสดง AlertView และ UIActivityIndicatorView แบบ Progress

iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)

แสดง AlertView และ UIActivityIndicatorView กำลังทำงาน








เพิ่มเติม
สำหรับตัวนี้อาจจะใช้แสดงในขณะที่ App กำลังทำงานหรือโหลดข้อมูลจาก Server ซึ่งจะเห็นว่าไม่มีปุ่มที่จะใช้ปิดหรือซ่อน แต่อเราจะใช้คำสั่ง

    [loading dismissWithClickedButtonIndex:0 animated:YES];
    [loading release];


ในการซ่อน Alert View เมื่อโปรแกรมทำงานเรียบร้อยแล้ว สามารถหาดูตัวอย่างได้จากบทความนี้

iOS/iPhone NSURLConnection Show Progress and Activity Indicator View (UIActivityIndicatorView)


   
Share


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


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


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-12-12 08:50:34 / 2017-03-26 00:22:05
  Download : Download  iOS/iPhone Activity Indicator View and AlertView (UIAlertView / UIActivityIndicatorView)
 Sponsored Links / Related

 
iOS/iPhone Activity Indicator View (ActivityIndicator,UIActivityIndicatorView) Example (iPhone,iPad)
Rating :

 
iOS/iPhone Progress View (UIProgressView) Example (iPhone,iPad)
Rating :

 
iOS/iPhone Image View and NSURLConnection ActivityIndicator Progress
Rating :

 
iOS/iPhone NSURLConnection Show Progress and Activity Indicator View (UIActivityIndicatorView)
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 03
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 อัตราราคา คลิกที่นี่