0

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

例如。“成本”行必须显示数字键盘供用户输入,而“郊区”行必须显示标准键盘供用户输入。

这里有一张图可以帮助大家。该单元需要标准键盘。

http://i.stack.imgur.com/rGFhC.png

4

2 回答 2

0

这很简单。你可以-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).
于 2013-01-14T10:17:35.393 回答
0

如果您在自定义单元格中放置一个文本字段以输入数据,那么

if (indexPath.row == 1)
{
     textfield.keyboardType = UIKeyboardTypeNumberPad; //(for number keypad)
}

有不同的键盘类型。

对于标准键盘,使用枚举UIKeyboardTypeDefault

在 -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;

}

希望这会帮助你。

于 2013-01-14T11:31:36.103 回答