【问题标题】:How to assign the alert message textfield input value to the button?如何将警报消息文本字段输入值分配给按钮?
【发布时间】:2012-03-12 04:39:38
【问题描述】:

如何将警报消息文本字段输入值分配给按钮?

在下面的代码中,我为 textfield 赋值,但要求是通过警报消息为按钮而不是 textfeild 赋值,帮助我解决 iPhone 中的问题。

-(IBAction)alertmessage{
     [self setingValue];       
}

 -(void)setingValue{
    myAlert = [[UIAlertView alloc] initWithTitle:@"Enter year" message:@"alert message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [myAlert addTextFieldWithValue:@"" label:@"entervalue"];     
    alertTextField=[myAlert textFieldAtIndex:0];
    alertTextField.keyboardType=UIKeyboardTypeAlphabet;
    alertTextField.clearsOnBeginEditing=YES;
    alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
    alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
    [myAlert show];
    [myAlert release];
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
    if ([buttonTitle isEqualToString:@"Ok"]) {
       yearSelection.text= alertTextField.text;
    }
}

如果我从警报文本字段输入键盘值作为必须分配或出现在按钮上的输入类型。

【问题讨论】:

  • 请确保在发布代码后格式化代码。
  • 您想为按钮分配什么值..?你的问题不是很清楚..

标签: iphone objective-c ios5 uibutton uialertview


【解决方案1】:
-(void)setingValue{

  myAlert = [[UIAlertView alloc] initWithTitle:@"Enter year" message:@"alert message"  
  delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
  alertTextField=[UITextfiled alloc]initwithFrame:CGRectFrame:(5,25,200,35)]; //set the frame as you need.
  alertTextField.Placeholder=@"Enter Value";
  alertTextField.keyboardType=UIKeyboardTypeAlphabet;
  alertTextField.clearsOnBeginEditing=YES;
  alertTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
  alertTextField.keyboardAppearance=UIKeyboardAppearanceAlert;
  [myAlert addSubview:alertTextFiedl];
  [alertTextField release];
  [myAlert show];
  [myAlert release];
}

【讨论】:

    猜你喜欢
    • 2012-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2021-07-19
    • 1970-01-01
    • 2022-01-02
    相关资源
    最近更新 更多