Image 根据具体情况更改键盘类型

Image 根据具体情况更改键盘类型,image,cocoa-touch,uitableview,Image,Cocoa Touch,Uitableview,我正在制作一个应用程序,其中有一个自定义的UITableViewCell,它有标准,然后用户键入答案。为了方便用户,我想根据选择的行更改键盘类型 “成本”行必须显示一个数字键盘供用户输入,“郊区”行必须显示标准键盘供用户输入 这是一张帮助你们的图片。这个单元需要标准键盘 这很简单。您可以修改-cellForRowAtIndexPath:如下: if (indexPath.row == 1) { [textField setKeyboardType:UIKeyboardTypeNumbe

我正在制作一个应用程序,其中有一个自定义的UITableViewCell,它有标准,然后用户键入答案。为了方便用户,我想根据选择的行更改键盘类型

“成本”行必须显示一个数字键盘供用户输入,“郊区”行必须显示标准键盘供用户输入

这是一张帮助你们的图片。这个单元需要标准键盘


这很简单。您可以修改
-cellForRowAtIndexPath:
如下:

if (indexPath.row == 1)
{
     [textField setKeyboardType:UIKeyboardTypeNumberPad];
}
else if ()
{
}..
一些键盘类型包括:

UIKeyboardTypeDefault,                // Default type for the current input method.
UIKeyboardTypeASCIICapable,           // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation,  // Numbers and assorted punctuation.
UIKeyboardTypeURL,                    // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad,              // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad,               // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad,           // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress,           // A type optimized for multiple email address entry (shows space @ . prominently).

如果要在自定义单元格中放置文本字段以输入数据,则

if (indexPath.row == 1)
{
     textfield.keyboardType = UIKeyboardTypeNumberPad; //(for number keypad)
}
有不同的键盘类型

对于标准键盘,请使用enum
UIKeyboardTypeDefault

In-cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath 
{

    UITableViewCell *cell = nil;

    static NSString *CellIdentifier = @"cellidentifier";

    CustomCell *tableCustomCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (tableCustomCell == nil)
    {
        [[NSBundle mainBundle]loadNibNamed:@"CustomCell" owner:self options:nil];
        tableCustomCell = self.customCell;
        self.customCell = nil;
    }
    //Here add the check for the textfields


    cell = tableCustomCell;
    return cell;

}
希望这对你有帮助