表格查看单元格格式

时间:2015-06-30 03:57:34

标签: ios objective-c uitableview

我正在玩待办事项列表中的Apple Dev教程,试图将其转化为我工作中的交付内容。我一直致力于NSString位置的格式化,以及NSNumber的总数,小费和小时百分比,没有运气。我试图获取数据,而不是正确对齐的标题。我尝试创建两个单元格(在注释代码中)但是这个"原型单元格"在故事板中只是覆盖它,并提供我在故事板中的原型单元格文本" Mow the Lawn"代替。有什么建议吗?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"ListPrototypeCell" forIndexPath:indexPath];

    // Configure the cell...

    cell.textLabel.numberOfLines = 0;  // 0 means no max.
    tableView.rowHeight = 100;

    ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.roundingIncrement = [NSNumber numberWithDouble:0.01];
    [formatter setNumberStyle:NSNumberFormatterCurrencyStyle];

    NSNumberFormatter *percentageFormatter = [[NSNumberFormatter alloc] init];
    //NSString *detailText = @"Location: @\nTotal: @\nTip: \nPercentage: %%";

    if(toDoItem.isCreditCard)
    {
      cell.textLabel.text = [NSString stringWithFormat:@"Location: %10@\nTotal: %10@\nTip: %@\nPercentage: %@%%", toDoItem.location, [formatter stringFromNumber:toDoItem.total], [formatter stringFromNumber:toDoItem.tip],[percentageFormatter stringFromNumber:toDoItem.percentage]];
         cell.detailTextLabel.text = @"Credit Card";
    }
    else
    {
        cell.textLabel.text = [NSString stringWithFormat:@"Location: %10@\nTotal: %10@\nTip: %@\nPercentage: %@%%", toDoItem.location, [formatter stringFromNumber:toDoItem.total], [formatter stringFromNumber:toDoItem.tip],[percentageFormatter stringFromNumber:toDoItem.percentage]];
        cell.textLabel.textAlignment = NSTextAlignmentLeft;
        cell.detailTextLabel.text = @"Location: @\nTotal: @\nTip: \nPercentage: %%";
        //cell.detailTextLabel.textAlignment = NSTextAlignmentRight;
        cell.detailTextLabel.text = @"";
    }

  /*  UILabel *lbl = [[UILabel alloc]init];
    lbl.text = @"Location: @\nTotal: @\nTip: \nPercentage: %%";
    [lbl setFrame:cell.textLabel.frame];// set frame which you want
    [lbl setBackgroundColor:[UIColor clearColor]];// set any color here
    //                 lbl.lineBreakMode = UILineBreakModeWordWrap; // set it if you want to height of UILable with its content (Multiple line)
    lbl.numberOfLines = 0;// Add this line // Set 0 if you want to multiple line.
    lbl.textAlignment =  NSTextAlignmentLeft;
    [cell.contentView addSubview:lbl];

    UILabel *lbl2 = [[UILabel alloc]init];
    lbl2.text = @"test2";
   // LogCGRect(cell.textLabel.frame);
    [lbl2 setFrame:cell.textLabel.frame];// set frame which you want
    [lbl2 setBackgroundColor:[UIColor clearColor]];// set any color here
    //                 lbl.lineBreakMode = UILineBreakModeWordWrap; // set it if you want to height of UILable with its content (Multiple line)
    lbl2.numberOfLines = 2;// Add this line // Set 0 if you want to multiple line.
    lbl2.textAlignment =  NSTextAlignmentRight;
    [cell.contentView addSubview:lbl2];
  */ 
    return cell;
}

0 个答案:

没有答案