-4

在此处输入图像描述

我想知道我怎样才能得到像上图这样的东西。你是怎么做到的,有人有一些示例代码吗?

4

3 回答 3

1

你需要为你的表格创建一个自定义单元格,设计你想要的单元格。放置 textView 或任何东西,并使用该自定义单元格加载您的表格。

于 2013-03-28T10:58:29.953 回答
0

它被称为自定义UITableViewCell,由两个控件组成

1 UILabel 
2 UITextField 

将这两个控件放入cellForRowAtIndexPath特定的帧大小。

或者

按原样放置整个代码。

- (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;
}
于 2013-03-28T11:00:00.957 回答
0

设计您的自定义单元格(如有必要,为您的标签使用自定义字体以获得确切的外观。)

定制单元设计

在此处输入图像描述

并像这样在索引委托方法处为行自定义单元格。

 - (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 *cellIdentifier=@"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;
    }
于 2013-03-28T11:06:13.043 回答