0

When I use alertView using below code, it shows me the warning

warning: Semantic Issue: Method '-addTextFieldWithValue:label:' not found (return type defaults to 'id') 

Here is the code:

    UIAlertView *alSave=[[UIAlertView alloc]initWithTitle:@"Save as" message:@"Title the note and click Save" delegate:self cancelButtonTitle:@"save" otherButtonTitles:@"cancel", nil];
    NSArray *arr=[noteObj.noteTitle componentsSeparatedByString:@" - "];
    app.longClickId = [noteObj.noteId integerValue];
    [alSave addTextFieldWithValue:[NSString stringWithFormat:@"%@",[arr objectAtIndex:0]] label:@"Note Name"];
   // show me warning at this place

    textField = [alSave textFieldAtIndex:0];
    textField.keyboardType = UIKeyboardTypeAlphabet;
    textField.keyboardAppearance = UIKeyboardAppearanceAlert;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;   // correction automatically

    [alSave show];
    if (app.NotePopOver!= nil) {
        [app.NotePopOver dismissPopoverAnimated:YES];

    }
    [alSave release];
Verbeia
  • 4,400
  • 2
  • 23
  • 44
Chirag Patel
  • 11,416
  • 3
  • 26
  • 38
  • 1
    possible duplicate of [warning: 'UIAlertView' may not respond to '-addTextFieldWithValue:label:'](http://stackoverflow.com/questions/2294910/warning-uialertview-may-not-respond-to-addtextfieldwithvaluelabel) – PengOne Nov 17 '11 at 05:29
  • and also '-textFieldAtIndex:' not found (return type defaults to 'id') – Chirag Patel Nov 17 '11 at 05:35
  • Again, you are using undocumented or non-existent methods. Check the documentation. If the method isn't there, a warning will ensue and Apple will likely reject the app. – PengOne Nov 17 '11 at 05:39

2 Answers2

2

If you use a private method (of which addTextFieldWithValue: is one), then Apple will most likely reject your app. You can achieve the same result with the following snippet, courtesy of this answer which credits a no longer working link:

UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Your title here!" message:@"this gets covered" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
UITextField *myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
[myTextField setBackgroundColor:[UIColor whiteColor]];
[myAlertView addSubview:myTextField];
CGAffineTransform myTransform = CGAffineTransformMakeTranslation(0.0, 130.0);
[myAlertView setTransform:myTransform];
[myAlertView show];
[myAlertView release];
Community
  • 1
  • 1
PengOne
  • 48,188
  • 17
  • 130
  • 149
1

That method is undocumented. You will have to create your own text field and then add it to the alert view.

sosborn
  • 14,676
  • 2
  • 42
  • 46