2016-03-31 6 views
1

Ich erstelle Tags innerhalb _ParentContentView Unteransicht in UITableView Cell. folgenden Code erstellen, um alle manuell Tags und kann Speicher für jeden Tags erhöhen und es ist SubviewsSo erstellen Sie mehrere Tags innerhalb von UITableViewCell und legen Sie Aktion für jede Tags

  • i Aktion wie für jeden Tag haben
  • ich alle Tags innerhalb tableivewCell haben möchten mit aus insdie Tabellenansicht Zelle Scrollen . mean tableviewCell sollte die Inhaltsgröße automatisch erhöhen/verringern.

    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

Antwort

0

wie diese Sie tun können.

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

Für Satz Zeilenhöhe nach ist es Inhalte, die Sie Tableview die beiden Eigenschaften

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

so wird es Höhe es nach Inhalt nehmen Zeile setzen soll.

nicht verwenden:

heightForRowAtIndexPath Methode, wenn es über Code.

Verwandte Themen