2013-03-28 60 views
-4

enter image description here某種文本字段 - 表格視圖

我想知道如何獲得像上面的圖像。你如何做到這一點,是否有人得到某種樣本代碼?

+0

即'UITextField'被添加到'UITableViewCell'子類中。 CUSTOM TABLEVIEWCELL – viral 2013-03-28 11:00:14

回答

0

設計您的自定義單元格(使用自定義字體爲標籤,以獲取準確的外觀,如果必要的。)

定製單元設計

enter image description here

並自定義行的單元格的像這樣的索引委託方法。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
    // static NSString *CellIdentifier = @"Cell"; 
    // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    // if (cell == nil) { 
    //  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    // } 
    //  
     // Configure the cell... 

     //Customiztion of cell 
     static NSString *[email protected]"cell"; 
     SampleTableCell *cell = (SampleTableCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

     if (cell == nil) 
     { 
      NSString *customeCellName = [NSString stringWithFormat:@"%@",[SampleTableCell class]]; 

      NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:customeCellName owner:self options:nil]; 

      for (id currentObject in topLevelObjects) 
      { 
       if ([currentObject isKindOfClass:[UITableViewCell class]]) 
       { 
        cell = (SampleTableCell *) currentObject; 
        break; 
       } 
      } 
     } 
     cell.label1.text = @"Server"; 
     cell.label2.text = @"vereist" 
     return cell; 
    } 
+0

我正在使用故事板 – Shinonuma 2013-03-28 13:37:45

1

您需要爲您的表格創建自定義單元格,設計您的單元格。把textView或任何東西,並加載您的表與該自定義單元格。

0

這就是所謂的定製UITableViewCell,有包括兩個控制

1 UILabel 
2 UITextField 

將這個兩個控制在cellForRowAtIndexPath與具體FRAM大小。

OR

把這個整個代碼,因爲它是。

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    self.tblView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 23) style:UITableViewStyleGrouped]; 
    self.tblView.delegate = self; 
    self.tblView.dataSource = self; 
    self.tblView.backgroundView = nil; 
    self.tblView.backgroundColor = [UIColor clearColor]; 
    self.tblView.separatorStyle = UITableViewCellSeparatorStyleNone; 
    [self.view addSubview:self.tblView]; 

    self.placeHolderValue = [[NSMutableArray alloc]initWithObjects:@"server ", @"account", @"Roof Coverings", @"Wall token", @"Roof", @"Floor", @"Guttering", nil]; 


    self.textFields = [NSMutableArray array]; 
    self.textLabels = [NSMutableArray array]; 

    for (int i = 0; i < self.placeHolderValue.count; i++) 
    { 
     UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(155.0, 0.0, 150.0, 44.0)]; 
     textFiled.placeholder = @"Vereist"; 
     textFiled.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; 
     textFiled.autocorrectionType = UITextAutocorrectionTypeNo; 
     textFiled.autocapitalizationType = UITextAutocapitalizationTypeNone; 
     textFiled.borderStyle = UITextBorderStyleNone; 
     textFiled.clearButtonMode = UITextFieldViewModeAlways; 
     textFiled.delegate = self; 
     textFiled.tag = i+1; 
     textFiled.font = [UIFont systemFontOfSize:14]; 
     if (self.listOfDetails.count > 0) 
     { 
      textFiled.text = [[self.listOfDetails objectAtIndex:0] objectForKey:[self.dbFieldName objectAtIndex:i]]; 
      isEmpty = NO; 
     } 
     [self.textFields addObject:textFiled]; 

     UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 140, 44)]; 
     lab.text = [self.placeHolderValue objectAtIndex:i]; 
     lab.textAlignment = NSTextAlignmentLeft; 
     lab.numberOfLines = 0; 
     lab.font = [UIFont systemFontOfSize:14]; 
     lab.backgroundColor = [UIColor clearColor]; 
     [self.textLabels addObject:lab]; 
    } 
} 

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return self.placeHolderValue.count; 
} 

// Customize the appearance of table view cells. 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    //static NSString *CellIdentifier = @"Cell"; 
    NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row]; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
     [cell.contentView addSubview:[self.textLabels objectAtIndex:indexPath.row]]; 
     [cell.contentView addSubview:[self.textFields objectAtIndex:indexPath.row]]; 
    } 
    return cell; 
} 
相關問題