2010-02-27 68 views
9

Tôi muốn tìm cách kích hoạt bộ chọn theo chương trình khiến bàn phím iPhone chuyển từ chữ này sang chữ số khác. Tôi biết rằng tôi có thể chuyển đổi loại bàn phím, nhưng tôi muốn biết nếu có cách nào để thực hiện việc này mà không cần chuyển loại bàn phím.Tôi có thể lập trình kích hoạt nút "chuyển sang bàn phím số" trên bàn phím iPhone

+0

là này cho UIWebView hoặc một số lớp con khác của UIView? EDIT: Xin lỗi, chỉ cần nhận thấy các thẻ uitextfield – conorgriffin

Trả lời

6

Bạn không thể chuyển đổi các bộ khóa (bàn phím chữ cái sang bàn phím số sang ký hiệu phím biểu tượng) theo chương trình, ít nhất là không được hỗ trợ công khai theo bất kỳ cách nào. Như bạn đã đề cập, bạn có thể thay đổi loại bàn phím hoặc giao diện của các đặc điểm đầu vào văn bản của bộ trả lời đầu tiên, nhưng điều này khác với chuyển đổi giữa các máy chủ khác nhau mà chỉ người dùng mới có thể thực hiện.

1

Có xem xét này:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString * cellIdentifier = @"CellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if(cell == nil) 
    { 
     cell = [ [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease]; 
     cell.textLabel.font = [UIFont boldSystemFontOfSize:14.0f]; 
     cell.textLabel.textColor = [UIColor whiteColor]; 
    } 

    UITextField * textField = [ [ UITextField alloc] initWithFrame:CGRectMake(55.0f, 10.0f, 230.0f, 31.0f)]; 
    textField.textColor = [UIColor whiteColor]; 

    textField.delegate = self; 
c this care fully ///////////if(indexPath.row == 0) 
c this care fully // textField.keyboardType = UIKeyboardTypeDefault; 
c this care fully //else 
c this care fully // textField.keyboardType = UIKeyboardTypePhonePad; 
    textField.autocorrectionType = UITextAutocorrectionTypeNo; 
    [cell.contentView addSubview:textField]; 

    if(indexPath.row == 0) 
    { 
     self.sender = textField; 
     cell.textLabel.text = @"From:"; 
    } 
    else 
    { 
     self.mobileNumber = textField; 
     cell.textLabel.text = @"To:"; 
    } 
    [textField release]; 
    if(indexPath.row == 1) 
    { 
     UIButton * contactsButton = [UIButton buttonWithType:UIButtonTypeContactAdd]; 
     [contactsButton addTarget:self action:@selector(addContact:) forControlEvents:UIControlEventTouchUpInside]; 
     cell.accessoryView = contactsButton; 

    } 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 

} 

Kiểm tra nơi tôi nhận xét "c chăm sóc này hoàn toàn"

Điều này sẽ giúp bạn chuyển đổi bàn phím lập trình.

+0

bạn có thể sửa chữa thụt đầu dòng trong mã của bạn? – rickharrison

6

Chỉ cần giải pháp thay thế: Khi bạn muốn thay đổi bàn phím của bàn phím hoạt động như từ bảng chữ cái sang phím số trong khi chỉnh sửa UITextField, trước tiên hãy đặt giá trị mới thành thuộc tính keyboardType của trường văn bản, sau đó gửi lại từ khóaFirstResponder, cuối cùng một thông báo trở thànhFirstResponder vào trường văn bản. Ví dụ.

textfield.keyboardType = UIKeyboardTypeNumberPad; 
[textField resignFirstResponder]; 
[textField becomeFirstResponder]; 

Swift:

textField.keyboardType = .numberPad 
textField.resignFirstResponder() 
textField.becomeFirstResponder() 

Hy vọng nó giúp ;-D

+0

Bất kỳ từ nào trên ứng dụng bị từ chối vì thực hiện việc này? –

+2

Sử dụng 'textField.reloadInputViews()' để thay thế! –

+0

@NikKov 'textField.reloadInputViews()' không hoạt động. – David

Các vấn đề liên quan