作者Phedra (Phedra)
看板MacDev
标题Re: [问题] 如何抓UIAlertView里面某个按钮的title?
时间Fri Mar 9 13:37:32 2012
使用 UIAlertView 配合实作 UIAlertViewDelegate 的方式,
其中 alertView:clickedButtonAtIndex: 事件可以取得使用者按下了哪颗按钮
例如:
- (void)alertView:(UIAlertView *)alertView
clickedButtonAtIndex:(NSInteger)buttonIndex
{
// buttonIndex 就是使用者按下的按钮索引值
// 取得使用者按下的按钮标题
NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
// 使用者按下了 Cancel 按钮时
if ([buttonTitle isEqualToString:@"Cancel"]) {
// Do Something
}
// 同上, 但是改用 buttonIndex 来判断
if (buttonIndex == alertView.cancelButtonIndex) {
// Do Something
}
}
另外补充下面一个我觉得还不错的 iOS 程式设计中文学习网站,
其中有一篇 UIAlertView 的教学文章刚好符合你的需求
http://furnacedigital.blogspot.com/p/index-search.html
(UIAlertView 判断使用者按下的按钮标题)
http://furnacedigital.blogspot.com/2010/12/alerts.html
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.173.29.186
※ 编辑: Phedra 来自: 218.173.29.186 (03/09 13:38)
※ 编辑: Phedra 来自: 218.173.35.177 (04/05 08:38)