반응형
ShakeJ
MNWorld
ShakeJ
전체 방문자
오늘
어제
  • 카테고리 N
    • Contact
    • 🤔그냥이야기
    • 📷사진이야기
    • 제주도에서 한달을 살아보았다
    • 옛글 N
      • 👇Blog
      • 공지사항
      • 이슈 N
      • 생각들
      • 👇취미
      • 건프라
      • 👇Review
      • 노래리뷰
      • 영화리뷰
      • 👇Travel Story
      • 2011 도쿄여행기
      • 2013 Google IO
      • 2013 Jeju
      • 2014 HONGKONG
      • 2014 Jeju
      • 2014 Sanfransis..
      • 2015 Lombok
      • 2016 HONGKONG
      • 2017 Saigon
      • 국내여행기
      • Photo Story
      • Growth
      • 👇Server
      • Ruby on the Rai..
      • Frontend
      • FullStack (MEAN..
      • Ubuntu
      • 👇Android
      • 안드로이드 프로그래밍
      • 번역본
      • 내어플이야기
      • 코드창고
      • 👇iOS
      • 아이폰 프로그래밍
      • 맥북 이야기
      • 👇Microsoft
      • ASP.NET
      • Silverlight
      • 윈도우 이야기
      • 👇IT Story
      • 모바일 이야기
      • 하드웨어 이야기 N
      • 네트워크 이야기
      • 프로그래밍이야기
      • Database이야기
      • 클라우드이야기
      • 프론트 이야기
      • 마케팅이야기
      • 그래픽 작업
      • 블로그 팁

블로그 메뉴

  • GuestBook

공지사항

인기 글

태그

  • 블로그 잡담
  • 블로그 팁
  • 블로그 운영
  • iOS 프로그래밍
  • 블로그 초보
  • 서울 출사지
  • 안드로이드 어플 추천
  • 블로그 관련
  • 무료배너제작
  • 티스토리 팁
  • 풍경사진
  • 티스토리 초대장
  • 블로그 운영하기
  • 블로그 꾸미기
  • 블로그 이야기
  • 초대장
  • 랩
  • 티스토리
  • 블로그 운영하면서
  • 블로그 만들기
  • shakej
  • 배너무료제작
  • 블로그 시작하기
  • D40 사진
  • asp.net
  • MNWorld
  • 배너교환
  • 윈도우폰7
  • 블로그 처음
  • 배너제작

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ShakeJ

MNWorld

옛글/아이폰 프로그래밍

[iOS프로그래밍] AlertView 버튼 클릭 시 기능 구현

2012. 5. 24. 11:11
반응형

 

Im creating a view in Xcode 4.3 and im unsure how to specify multiple UIAlertView's that have their own buttons with separate actions. Currently, my alerts have their own buttons, but the same actions. Below is my code.

-(IBAction)altdev {
    UIAlertView*alert =[[UIAlertView alloc]

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue",nil];
[alert show];
}

-(IBAction)donate {
    UIAlertView*alert =[[UIAlertView alloc]

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue",nil];
    [alert show];
}

-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex ==1){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.examplesite1.com"]];
         }
}


-(void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex ==1){
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"examplesite2.com"]];
    }
}  

Thanks for any help!

xcode button multiple uialertview ibaction

 feedback

1 Answer

activeoldestvotes

 

There is a useful property tag for UIView(which UIAlertView subclass from). You can set different tag for each alert view.

UPDATE:

#define TAG_DEV 1
#define TAG_DONATE 2

-(IBAction)altdev {
    UIAlertView*alert =[[UIAlertView alloc]

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue",nil];
   alert.tag = TAG_DEV;
   [alert show];
}

-(IBAction)donate {
    UIAlertView*alert =[[UIAlertView alloc]

                          initWithTitle:@"titleGoesHere"
                          message:@"messageGoesHere"
                          delegate:self
                          cancelButtonTitle:@"Cancel"
                          otherButtonTitles:@"Continue",nil];
    alert.tag = TAG_DONATE;
    [alert show];
}

-(void)alertView:(UIAlertView*)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(alertView.tag == TAG_DEV){// handle the altdev
      ...
    }elseif(alertView.tag == TAG_DONATE){// handle the donate

    }
}







반응형
저작자표시 비영리 변경금지

'옛글 > 아이폰 프로그래밍' 카테고리의 다른 글

Cocos 2D for iPhone 개념잡기  (0) 2012.06.19
[iOS프로그래밍]Webview Javascript&URL Catch하기  (4) 2012.06.08
[iOS프로그래밍] Navigation Bar 에 Button 붙이기  (0) 2012.05.24
[iOS프로그래밍] Objective-C Code Rule  (0) 2012.05.16
[iOS프로그래밍] 뷰 안에 뷰는 관리하지 않는다!  (1) 2012.05.15
    추천글👇
    • [📷사진이야기] 붉은 호치민의 노을
    ShakeJ
    ShakeJ

    티스토리툴바