例子:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:selectTitle delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定", nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
// 設置輸入框的內容
[alert textFieldAtIndex:0].text = selectTitle;
// 用以傳遞選中的行索引
alert.tag = indexPath.row; //
[alert show];
代理方法
// Called when a button is clicked. The view will be automatically dismissed after this call returns
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button.
// If not defined in the delegate, we simulate a click in the cancel button
- (void)alertViewCancel:(UIAlertView *)alertView;
- (void)willPresentAlertView:(UIAlertView *)alertView; // before animation and showing view
- (void)didPresentAlertView:(UIAlertView *)alertView; // after animation
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex; // before animation and hiding view
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; // after animation
// Called after edits in any of the default fields added by the style
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;
例如:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 1) {
// ……….
}
}