繁体   English   中英

如何在iOS中的UITableView中更改行的位置

[英]How to change the position of a row in UITableView in ios

我使用以下教程创建了可扩展的tableview: Expandable-Collapsable-TableView

我的图片:

在此处输入图片说明

我想缩小左侧各行之间的间距。 距离太大。 任何人都可以帮助我定位行。

这就是所谓的“缩进”。

如果要在情节提要/ xib中使用原型单元,则可以直接从单元的“属性”检查器中更改其缩进。

在此处输入图片说明

(如果缩进级别为0,则不必将宽度更改为0)。

如果没有,您可以通过编程方式更改它,例如:

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.indentationLevel = 0;   // No indentation level.
    cell.indentationWidth = 0;   // It's redundant if the level is 0.

}

打开createCellWithTitle方法,改变cell.indentationWidth为你的自我

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *Title= [[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Name"];

return [self createCellWithTitle:Title image:[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"Image name"] indexPath:indexPath];
 } 



- (UITableViewCell*)createCellWithTitle:(NSString *)title image:(UIImage *)image  indexPath:(NSIndexPath*)indexPath
{
    [cell setIndentationLevel:[[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];
    cell.indentationWidth = 40;   //change the width as your self

 }
- (UITableViewCell*)createCellWithTitle:(NSString *)title image:(UIImage *)image  indexPath:(NSIndexPath*)indexPath
{
    NSString *CellIdentifier = @"Cell";
    ExpandableTableViewCell* cell = [self.menuTableView dequeueReusableCellWithIdentifier:CellIdentifier];
        UIView *bgView = [[UIView alloc] init];
        bgView.backgroundColor = [UIColor grayColor];
        cell.selectedBackgroundView = bgView;
        cell.lblTitle.text = title;
        cell.lblTitle.textColor = [UIColor blackColor];

        [cell setIndentationLevel:[[[self.itemsInTable objectAtIndex:indexPath.row] valueForKey:@"level"] intValue]];

        //**replace your x position**
        cell.indentationWidth = 10;

        float indentPoints = cell.indentationLevel * cell.indentationWidth;

        cell.contentView.frame = CGRectMake(indentPoints,cell.contentView.frame.origin.y,cell.contentView.frame.size.width - indentPoints,cell.contentView.frame.size.height);

        NSDictionary *d1=[self.itemsInTable objectAtIndex:indexPath.row] ;

        if([d1 valueForKey:@"SubItems"])
        {
            cell.btnExpand.alpha = 1.0;
            [cell.btnExpand addTarget:self action:@selector(showSubItems:) forControlEvents:UIControlEventTouchUpInside];
        }
        else
        {
            cell.btnExpand.alpha = 0.0;
        }
        return cell;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM