본문 바로가기
Programming/iOS

UIAlertView에 UITextField 넣기.

by 신규하 2010. 2. 19.
UIAlertView에 textfield를 넣을 일이 있어서..
구글링을 해서.. 아래의 주소를 찾았습니다.


열심히 이걸 활용해서.. 프로그램 짜고 올렸는데..
흠...

The following non-public APIs are included in your application:
addTextFieldWithValue:label:
textFieldAtIndex:

If you have defined methods in your source code with the same names as the above mentioned APIs, we suggest altering your method names so that they no longer collide with Apple's private APIs to avoid your application being flagged with future submissions.
이번에는 올려주지만, 다음부터는 쓰지 말라고 하네요.
인터넷에서 별 생각 없이 받아서 사용한 코드가 이런 무서운 화를 부를수 있다는 교훈을 얻었습니다.
솔직히, 일부러 사용한것도 아니구,  어떤게 no-public API인지 매번 확인 할 수도 없으니.
난감하네요..

그래서 찾은 해결책은..

이 주소 입니다.


File.h
UITextField *textField;
UITextField *textField2;
File.m
UIAlertView *prompt = [[UIAlertView alloc] initWithTitle:@"Username and password" message:@"\n\n\n" // 중요!! 칸을 내려주는 역할을 합니다. delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Enter", nil];
textField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)]; [textField setBackgroundColor:[UIColor whiteColor]]; [textField setPlaceholder:@"username"]; [prompt addSubview:textField];
textField2 = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)]; [textField2 setBackgroundColor:[UIColor whiteColor]]; [textField2 setPlaceholder:@"password"]; [textField2 setSecureTextEntry:YES]; [prompt addSubview:textField2];
// AlertView의 위치를 이동 시켜 줌. [prompt setTransform:CGAffineTransformMakeTranslation(0.0, 110.0)]; [prompt show]; [prompt release];

 // textfield에 커서를 보내고 키보드를 표시 해 줌. [textField becomeFirstResponder];

포럼에서 이 주제로 많은 대화가 오가던데..
문제는 창의 위치와 키보드가 안 나오는 문제, 텍스필드를 넣었지만 크기가 늘어나지 않는 문제 등이 있었습니다.

그나마, 약간의 트릭이 있긴 하지만, 모두 해결된 코드라서 이렇게 옮겨 봅니다.

참고 주소

 

댓글