iPhone: UITextField внутри ячейки TableView? - PullRequest
1 голос
/ 24 мая 2010

Я пытаюсь программно добавить UITextFiled в одну из моих ячеек таблицы. Как бы я это сделал?

Предполагая, что это в следующем методе, какой код я бы использовал?

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
        cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
        // Don't let the user click when not in editing mode
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    switch (indexPath.row) {
        case 0: 
            cell.textLabel.text = @"Title";
            // This is where I want to add a text field
            cell.detailTextLabel.text = @"test";
            cell.editing = YES;
        break;
    }

    return cell;
}

1 Ответ

1 голос
/ 24 мая 2010

попробуйте это:

[cell.contentView addSubview:[[[UITextField alloc] initWithFrame:CGRectMake(...)] autorelease]];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...