이 메서드에서 textfield를 가져 와서 textfieldshouldreturn을 호출 할 수 있습니까? UIView에 대리자 속성이 없다는 것은 당연한 일이지만, 프로토콜을 준수하는 메서드 내에서 만든 UIView를 만드는 방법을 모르겠습니다. 대표단에 관한 여러 게시물을 보았습니다.하지만 시도한 모든 것은 효과가 없습니다. 나는 그 무언가 간단하다고 확신합니다. 미리 감사드립니다. TextFieldShoudReturn이 호출되지 않음
- (void) launchCreateNewListActionSheet{
self.listActionSheet= [[UIActionSheet alloc] initWithTitle:@"Create A New List"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIView *addToNewList = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, 464)];
addToNewList.backgroundColor = [UIColor whiteColor];
UILabel *addToNewListLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 23, 100, 20)];
addToNewListLabel.text = @"List Name: ";
UITextField *enterNewListName = [[UITextField alloc] initWithFrame:CGRectMake(100, 20, 180, 30)];
enterNewListName.layer.borderWidth = 1;
enterNewListName.layer.borderColor = [[UIColor blackColor] CGColor];
enterNewListName.delegate = self;
[addToNewList addSubview:addToNewListLabel];
[addToNewList addSubview:enterNewListName];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(addToExistingList)];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelListPicker)];
UIBarButtonItem *fixedCenter = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedCenter.width = 180.0f;
UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[toolbar sizeToFit];
[toolbar setItems:@[cancelBtn, fixedCenter, doneBtn] animated:YES];
[self.listActionSheet addSubview:toolbar];
[self.listActionSheet addSubview:addToNewList];
[self.listActionSheet showInView:self.view];
[self.listActionSheet setBounds:CGRectMake(0,0,320, 464)];
}
여기에 내 .h 파일이 있습니다. 나는 다른 메소드에서 텍스트 필드를 위해 작업하면서 구현했다.
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if([self.textFieldArray containsObject:textField])
{
NSUInteger index = [self.textFieldArray indexOfObject:textField];
NSNumber *newQuantity = [NSNumber numberWithInteger:[textField.text integerValue]];
[self.quantityArray replaceObjectAtIndex:index withObject:newQuantity];
NSLog(@"Your new quantity is: %@", newQuantity);
}
[textField resignFirstResponder];
return YES;
}
중단 점을 사용하여 TextFieldShoudReturn 메서드가 호출되지 않았는지 확인 했습니까? –
NSlog가 호출되는지 여부를 확인합니다. –
질문에 TextFieldShoudReturn 메서드를 편집 할 수 있습니까? –