How to Implement DataSheet

扶醉桌前 提交于 2019-12-25 03:59:09

问题


I want to implement data sheet to display history of user. I want to implement that design like this:

But I dont know how to do that...Can anyone please help me

Edit:


回答1:


Add the horizontal line at the specific position and the label at the position and it will look like this.

Create a tableview and than in cellForRowAtIndexPath method add this code..

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

    NSString *SimpleTableIdentifier;
    UITableViewCell * cell;

    SimpleTableIdentifier = @"SimpleTableIdentifier";
    cell = [tableView  dequeueReusableCellWithIdentifier: nil];

    if(cell == nil) {

        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:SimpleTableIdentifier];


        UILabel * numLbl = [[UILabel alloc] initWithFrame:CGRectMake(0,5,33,30)];
        numLbl.text = @"1";
        [numLbl setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
        numLbl.backgroundColor = [UIColor clearColor];
        [cell addSubview:numLbl];

        UILabel * nameLbl = [[UILabel alloc] initWithFrame:CGRectMake(30,5,50,30)];
        nameLbl.text = @"john%Lakeview";
        [nameLbl setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
        nameLbl.backgroundColor = [UIColor clearColor];
        [cell addSubview:nameLbl];


        //create a hoizontal separator in cell to display it like column
        UIView* hSeparatorview1 = [[UIView alloc] initWithFrame:CGRectMake(25, 0, 1, 30)];
        hSeparatorview1.backgroundColor = [UIColor blackColor];
        hSeparatorview1.tag = 1;
        [cell addSubview:hSeparatorview1];

        UIView* hSeparatorview2 = [[UIView alloc] initWithFrame:CGRectMake(85, 0, 1, 30)];
        hSeparatorview2.backgroundColor = [UIColor blackColor];
        hSeparatorview2.tag = 2;
        [cell addSubview:hSeparatorview2];
    }

    return cell;
}

//this method is used to set the hight of the tableview cell
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath      *)indexPath;
{
    return 30;
}

I have created it for only two label and two horizontal view but you can create as many as you like.

And yes dot forget to place this code in didSelectRowAtIndexPath otherwise horizontal view will disappear when user click the cell.

- (void)tableView:(UITableView *)atableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //get the cell which is selected
    UITableViewCell *selectedCell = [atableView cellForRowAtIndexPath:indexPath];

    //set cell horizontal saparator view color of selected cell bcoz when cell selected all view color is gone
    UIView *hSeparatorview1=[selectedCell viewWithTag:1];
    hSeparatorview1.backgroundColor = [UIColor blackColor];

    UIView *hSeparatorview2=[selectedCell viewWithTag:2];
    hSeparatorview2.backgroundColor = [UIColor blackColor];

}



回答2:


Better to try with Custom tableview Cell for text,and UIViews for lines.I'm also done the same in my app.



来源:https://stackoverflow.com/questions/20779979/how-to-implement-datasheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!