簡體   English   中英

iPhone使用UITextFields填充表

[英]iPhone Populating Table With UITextFields

可以用UITextField類型填充表格嗎? 如果是這樣,怎么辦?

我嘗試了幾種不同的實現,盡管每種都失敗了。 請讓我知道您過去是否取得了類似的成就以及您如何取得的成就。

你可以嘗試一下MonoTouch.Dialog

創建一個自定義UITableViewCell

在tableViewController的viewDidLoad中注冊它:

[self.tableView registerClass:[TableCell class] forCellReuseIdentifier:@"tableCell"];

確保tableView:cellForRowAtIndexPath:看起來像這樣:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"tableCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

在自定義單元格的initWithStyle:reuseIdentifier中:

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self.contentView setBackgroundColor:[UIColor redColor]];
        UITextField *textField= [[UITextField alloc] initWithFrame:CGRectMake(10, 0, 600, self.bounds.size.height)];
        [textField setBackgroundColor:[UIColor greenColor]];
        [self addSubview:textField];
    }
    return self;

}

需要調整textField的大小,自動換行和許多其他實用位來使輸入和輸出正常工作,但這會將textField放入tableViewCell中。

希望能有所幫助,史蒂夫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM