6

我是 iphone 的新手。我正在为我的项目做提醒应用程序。我想从 uiactionsheet 获取提醒标题和数据和时间等输入值。我在 actionsheet 中创建了 datepicker 和 uitextfield。操作表与文本字段一起出现。当我单击文本字段时,键盘出现但无法正常工作。当我输入时,它们在文本字段中不可见

-(void)btnSetRemainderTapped:(id)sender
{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Select reminder date and time"
                                                  delegate:self
                                         cancelButtonTitle:@"Cancel"
                                    destructiveButtonTitle:@"Save"
                                         otherButtonTitles:nil,nil];
 menu.tag =10;
[menu showInView:self.view];
menu.userInteractionEnabled=YES;

UITextField  *txtReminderTitle= [[UITextField alloc] initWithFrame:CGRectMake(20.0, 180, 280.0, 40.0)];
[txtReminderTitle setTag:99];
[txtReminderTitle setBackgroundColor:[UIColor whiteColor]];
[txtReminderTitle setFont:[UIFont boldSystemFontOfSize:17]];
[txtReminderTitle setBorderStyle:UITextBorderStyleNone];
[txtReminderTitle setTextAlignment:UITextAlignmentCenter];
txtReminderTitle.borderStyle = UITextBorderStyleRoundedRect;
txtReminderTitle.keyboardType = UIKeyboardTypeDefault;
txtReminderTitle.returnKeyType = UIReturnKeyDone;
txtReminderTitle.delegate =self;
[menu addSubview:txtReminderTitle];

UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDateAndTime;
pickerView.tag =9999;
[menu addSubview:pickerView];

CGRect menuRect = menu.frame;
NSInteger orgHeight = menuRect.size.height;
menuRect.origin.y -= 270; //height of picker
menuRect.size.height = orgHeight+270;
menu.frame = menuRect;

CGRect pickerRect = CGRectMake(20, 250, 280, 200);
pickerView.frame = pickerRect;

}

-(void) actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex
  {
UIDatePicker *datePicker = (UIDatePicker *)[actionSheet viewWithTag:9999];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterLongStyle;
[df setTimeStyle:NSDateFormatterShortStyle];
UITextField * txtReminderTitle = (UITextField *)[actionSheet viewWithTag:99];
   NSLog(@"%@",txtReminderTitle.text);  //it print null value
  }

我不确定为什么它不接受来自键盘的输入。有什么建议么?

4

2 回答 2

4

我发现,当你添加UITextFieldUIActionSheetthen时,UITextField它仍然保留在UIActionSheet. 所以你需要把UITextField上面那个UIActionSheet方法输入任何文本
[menu addSubview:txtReminderTitle];行不通。UITextField

使用以下代码添加UITextField

UIWindow *appWindow = [UIApplication sharedApplication].keyWindow;
[appWindow insertSubview:txtReminderTitle aboveSubview:menu];

只需要更改如何添加UITextField

于 2013-03-06T12:43:45.453 回答
0

使用自定义 UIActionSheet 。像下面这样
1) 添加新的 UIViewController
2) 声明一个 UITextField

@interface ViewController  
{
            UITextField *TextField;

    }

3) 添加 ActionSheet & TextField 的代表

@interface ViewController : UIViewController <UIActionSheetDelegate, UITextFieldDelegate> {

        UITextField *TextField;

    }

4)现在实现方法

看到我在stackoverflow上看到的这个链接

于 2013-02-12T05:12:38.697 回答