[英]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.