2016-03-31 12 views
1

にUITableViewCellの内部に複数のタグと設定されたアクションを作成します。私は テーブルビューセルinsdieスクロールアウトしてtableivewCell内のすべてのタグを持っていると私はそれぞれのタグ は、どのように私はのUITableViewのセルに_ParentContentViewサブビュー内のタグを作成していた各タグ

  • のためのアクションを持っていると次のコードすべて手動でタグを作成し、各タグのメモリを増やす可能性があり、それがサブビュー

    • です。平均tableviewCellは、 のコンテンツサイズを自動的に増減する必要があります。あなたが行うことができます。このような

      SpecialityCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath]; 
      cell.selectionStyle = UITableViewCellSelectionStyleNone; 
      int xPosition = 0; 
      int yPosition = 0; 
      for (NSInteger buttonCount = 0; buttonCount<=dummyString.count-1; buttonCount++) 
      { 
      
      UIView *parentView = [[UIView alloc]init]; 
      parentView.frame = CGRectMake(10, 0, 150, 40); 
      [parentView setFrame:CGRectMake(xPosition+10, yPosition,100, 25)]; 
      
      xPosition = xPosition+130; 
      
      parentView.backgroundColor = [UIColor blackColor]; 
      parentView.alpha = 0.5; 
      parentView.layer.cornerRadius = 15; 
      
      UIImageView *childView =[[UIImageView alloc]init]; 
      childView.frame = CGRectMake(5, (parentView.frame.size.height-20)/2, 20, 20); 
      childView.alpha = 1.0; 
      childView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",[appDelegate.topinImageArray objectAtIndex:3]]]; 
      childView.layer.cornerRadius = 10; 
      [parentView addSubview:childView]; 
      UILabel *nameLabel = [[UILabel alloc] init]; 
      
      nameLabel.frame = CGRectMake(childView.frame.size.width+10, (parentView.frame.size.height-30)/2, 80, 30); 
      nameLabel.text = [NSString stringWithFormat:@"%@", [dummyString objectAtIndex:buttonCount]]; 
      nameLabel.textColor = [UIColor whiteColor]; 
      [parentView addSubview:nameLabel]; 
      
      [cell._ParantContentView addSubview:parentView]; 
      if((buttonCount+1)%3==0)//4 means how many buttons you need for a row 
            { 
             yPosition+= 50; 
             xPosition= 10; 
            } 
      

      }

    code output

  • 答えて

    0

    。セットの行の高さについては

    label1 = (UILabel*)[cell.contentView viewWithTag:401]; 
         CGFloat widthLabelHeader = CGRectGetWidth(orderTable.frame)/7; 
         if(!label1) 
    
         { 
    
          label1 = [[UILabel alloc]init]; 
          label1.frame = CGRectMake(0, 0, widthLabelHeader, 60); 
          label1.layer.borderWidth = 0.5; 
          label1.tag = 401; 
          label1.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          [cell.contentView addSubview:label1]; 
         } 
         label1.textAlignment = NSTextAlignmentCenter; 
    
         label2 = (UILabel*)[cell.contentView viewWithTag:402]; 
         if(!label2) 
    
         { 
    
          label2 = [[UILabel alloc]init]; 
          label2.frame = CGRectMake(CGRectGetMaxX(label1.frame), 0, widthLabelHeader, 60); 
          label2.layer.borderWidth = 0.5; 
          label2.tag = 402; 
          label2.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          [cell.contentView addSubview:label2]; 
         } 
         label2.textAlignment = NSTextAlignmentCenter; 
    
    
         label3 = (UILabel*)[cell.contentView viewWithTag:403]; 
         if(!label3) 
    
         { 
    
          label3 = [[UILabel alloc]init]; 
          label3.frame = CGRectMake(CGRectGetMaxX(label2.frame), 0, widthLabelHeader, 60); 
          label3.layer.borderWidth = 0.5; 
          label3.tag = 403; 
          label3.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          [cell.contentView addSubview:label3]; 
         } 
         label3.textAlignment = NSTextAlignmentCenter; 
    
    
         label4 = (UILabel*)[cell.contentView viewWithTag:404]; 
         if(!label4) 
    
         { 
    
          label4 = [[UILabel alloc]init]; 
          label4.frame = CGRectMake(CGRectGetMaxX(label3.frame), 0, widthLabelHeader, 60); 
          label4.layer.borderWidth = 0.5; 
          label4.tag = 404; 
          label4.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          label4.numberOfLines = 4; 
          [cell.contentView addSubview:label4]; 
         } 
         label4.textAlignment = NSTextAlignmentCenter; 
    
    
         label5 = (UILabel*)[cell.contentView viewWithTag:405]; 
         if(!label5) 
    
         { 
    
          label5 = [[UILabel alloc]init]; 
          label5.frame = CGRectMake(CGRectGetMaxX(label4.frame), 0, widthLabelHeader, 60); 
          label5.layer.borderWidth = 0.5; 
          label5.tag = 405; 
          label5.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          [cell.contentView addSubview:label5]; 
         } 
         label5.textAlignment = NSTextAlignmentCenter; 
    
    
         label6 = (UILabel*)[cell.contentView viewWithTag:406]; 
         if(!label6) 
    
         { 
    
          label6 = [[UILabel alloc]init]; 
          label6.frame = CGRectMake(CGRectGetMaxX(label5.frame), 0, widthLabelHeader, 60); 
          label6.layer.borderWidth = 0.5; 
          label6.tag = 406; 
          label6.font = [UIFont fontWithName:@"LaoSangamMN" size:14]; 
          [cell.contentView addSubview:label6]; 
         } 
         label6.textAlignment = NSTextAlignmentCenter; 
    
    
    
          UIButton *editBtn = (UIButton*)[cell.contentView viewWithTag:407]; 
          if(!editBtn) 
          { 
    
          editBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
          editBtn.frame = CGRectMake(CGRectGetMaxX(label6.frame), 0, widthLabelHeader, 60); 
    
          editBtn.layer.borderWidth = 2.5; 
          [editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside]; 
          [editBtn setTintColor:[UIColor blackColor]]; 
           editBtn.tag = 407; 
    
           [cell.contentView addSubview:editBtn]; 
    
           UIImageView *editimg = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(editBtn.frame),0, CGRectGetWidth(label6.frame), 60)]; 
           [editimg setImage:[UIImage imageNamed:@"edit-01.png"]]; 
           [cell.contentView addSubview:editimg]; 
          } 
         dict1 = [arrayFiltered objectAtIndex:indexPath.row]; 
         if(dict1) 
         { 
    
          NSString *strName = [dict1 objectForKey:@"i_name"]; 
          label1.text = @""; 
          label1.text = strName; 
          label1.backgroundColor = [UIColor whiteColor]; 
          label1.numberOfLines = 2; 
    
          label2.text = @""; 
          label2.text = [dict1 objectForKey:@"i_code" ]; 
          label2.backgroundColor = [UIColor whiteColor]; 
          label2.numberOfLines = 2; 
    
          NSString *strCategory = [dict1 objectForKey:@"i_category"]; 
    
          NSArray *arrValuesTempCat = [strCategory componentsSeparatedByString:@","]; 
          NSMutableArray *arrKeyTempCat = [NSMutableArray new]; 
    
          for (int i = 0; i < arrValuesTempCat.count; i++) 
          { 
           NSString *strValue = [arrValuesTempCat objectAtIndex:i]; 
           if ([[categoryDict allKeys] containsObject:strValue]) { 
    
            NSString *str = [categoryDict objectForKey:strValue]; 
            if (str.length > 0) 
            { 
             [arrKeyTempCat addObject:str]; 
            } 
           } 
          } 
          if ([arrKeyTempCat containsObject:@""]) 
          { 
           [arrKeyTempCat removeObject:@""]; 
          } 
    
          if ([arrKeyTempCat containsObject:@" "]) 
          { 
           [arrKeyTempCat removeObject:@" "]; 
          } 
    
          NSString *strCategoryKeysParam = nil; 
          if (arrKeyTempCat.count == 1) 
          { 
           strCategoryKeysParam = [arrKeyTempCat objectAtIndex:0]; 
          } 
          else 
          { 
           strCategoryKeysParam = [arrKeyTempCat componentsJoinedByString:@","]; 
          } 
    
    
    
          label3.text= @""; 
          label3.text = strCategoryKeysParam; 
          label3.backgroundColor = [UIColor whiteColor]; 
          label3.numberOfLines = 2; 
    
          NSString *strElements = [dict1 objectForKey:@"i_elements"]; 
          NSArray *arrKeysTemp = [strElements componentsSeparatedByString:@","]; 
          NSMutableArray *arrValuesTemp = [NSMutableArray new]; 
    
          for (int i = 0; i < arrKeysTemp.count; i++) 
          { 
           NSString *strKey = [arrKeysTemp objectAtIndex:i]; 
           if ([[elementsDict allKeys] containsObject:strKey]) { 
            NSString *strValue = [elementsDict objectForKey:strKey]; 
            [arrValuesTemp addObject:strValue]; 
           } 
          } 
    
    
          NSString *strValues = [arrValuesTemp componentsJoinedByString:@","]; 
          label4.text = @""; 
          label4.text = strValues; 
          label4.backgroundColor = [UIColor whiteColor]; 
    
    
          label5.text = @""; 
          label5.text = [dict1 objectForKey:@"i_quantity_produced" ]; 
          label5.backgroundColor = [UIColor whiteColor]; 
    
          label6.text = @""; 
          label6.text = [dict1 objectForKey:@"active_status" ]; 
          label6.backgroundColor = [UIColor whiteColor]; 
    
    
          [editBtn setTitle:@"" forState:UIControlStateNormal]; 
    
    
          NSString *idStr = [NSString stringWithFormat:@"%d",[[dict1 objectForKey:@"i_id"] intValue]]; 
          NSLog(@"ids : %@, dict : %@",idStr, dict1); 
           [editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside]; 
          editBtn.accessibilityIdentifier = idStr; 
          NSString *strID = editBtn.accessibilityIdentifier; 
          NSLog(@"str ID : %@",strID); 
    
    
          editItemId = [[dict1 objectForKey:@"i_id"]intValue]; 
          NSLog(@"Edited Item : %d",editItemId); 
    
    
          // [appDelegate hideIndicator]; 
    
          } 
        } 
    
    0

    それの内容に応じて、あなたは、テーブルビューの二つの性質

    _tableViewOne.estimatedRowHeight = 50; //minimum row height 
    _tableViewOne.rowHeight = UITableViewAutomaticDimension; 
    

    を設定する必要がありますので、それはそれの内容に応じて行の高さになります。

    使用しないでください。コードの上に使用して

    heightForRowAtIndexPath方法を。

    関連する問題