How to move the buttons in a UIAlertView to make room for an inserted UITextField?

后端 未结 8 780
挽巷
挽巷 2020-12-24 00:07

[EDIT] Hmm. Perhaps this question should be titled \"what is the default user-input dialog view called in CocoaTouch?\" I realize that I can create an entire view that is

8条回答
  •  忘掉有多难
    2020-12-24 00:24

    Zoul proposed the best method, to capture user input just do:

    a) Add the UITextFieldDelegate protocol to your class.

    b) Do something like

        UIAlertView *insertScore = [UIAlertView new];
        [insertScore setDelegate:self];
        [insertScore setTitle:@"New Title!"];
        [insertScore addButtonWithTitle:@"Cancel"];
        [insertScore addButtonWithTitle:@"Ok"];
    
        insertScore.message = @"\n";
    
        [insertScore addTextFieldWithValue:@"Input" label:@"player"];
    
        [[insertScore textField] setDelegate:self];
    
        [insertScore show]; 
    
        [insertScore release];
    

    c) The crucial part was to set the delegate of the textField to self, then to access data you can simply:

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    {
      NSLog(@"%@",[[alertView textField] text]);
    }
    

    Hope this helps someone, since I had to think a bit to get it right.

提交回复
热议问题