开发者

iPhone: UITextField inside TableView cell?

I am trying to programatically add a UITextFiled inside one of my tableview cells. How would I do this?

Assuming it is in the following method, what code would I use?

- (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 = UIT开发者_如何转开发ableViewCellSelectionStyleNone;
    }

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


try this:

[cell.contentView addSubview:[[[UITextField alloc] initWithFrame:CGRectMake(...)] autorelease]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜