2011-06-21 155 views
2

我一直試圖這樣做好幾天,但無濟於事。我也讓自己陷入了混亂之中。現在我真的很困惑我應該如何處理這個問題。在哪裏開始一個新的.h和.m文件。 :/UITableViewCell中的UITextField

我的目標是把一個UITextField放在幾個UITableViewCell中。就像這樣:

enter image description here

這:

enter image description here

有人可以幫助我某種教程?

謝謝。

回答

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

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:kCellIdentifier] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
     if (indexPath.row== 0) { 
      UITextField *TextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
      TextField.adjustsFontSizeToFitWidth = YES; 
      TextField.textColor = [UIColor blackColor]; 
       TextField.placeholder = @"mathie"; 
       [cell addSubview:TextField]; 
      } 
return cell; 
} 
+0

不應該調整文本字段的高度,以便填充單元格高度以便於選擇? –

0

檢查下面的蘋果默認教程。

這對你很有幫助。

https://developer.apple.com/library/prerelease/ios/#samplecode/AdvancedTableViewCells/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009111

這是關於 「AdvancedTableViewCells」。

它會要求登錄到你的蘋果帳戶。所以只需登錄,然後下載示例。

+0

對不起,該教程並不能說明在UITableViewCell中給出UITextField。你知道其他人與我發佈的圖片顯示的登錄功能類似嗎?謝謝。 –

+0

哦!好。目前,我沒有。如果有的話就讓你知道。 –

1

您可以創建一個由UITableViewCell組成的新的NIB。一旦你有了,你可以添加任何其他的UI元素,在你的情況下,UITextField。

在你的代碼可以調用您的自定義的UITableViewCell這樣的:

UITableViewCell *cell = [saleItemsTableView dequeueReusableCellWithIdentifier:cellIndedifier]; 

if (cell == nil) 
{ 
    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; 
    cell = saleItemsCell; 
} 

希望這有助於。

問候

+0

我必須編輯這個答案! –

+0

嗯...以編程方式繪製它會更容易嗎?我讀過幾個論壇,說加載nib文件會降低應用程序的速度?你知道如何繪製它們而不是觸摸筆尖嗎?謝謝。 –

+0

不是真的,如果你想要做的只是加載一些簡單的UITextField對象,我真的不知道它會對性能產生什麼影響。 – RynoB

相關問題