Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 9th, 2012  |  syntax: None  |  size: 9.79 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Contents in the UItableViewcell are not displayed after inserting new contents in cell
  2. - (void)viewDidLoad
  3. {
  4. [super viewDidLoad];
  5.  
  6.  
  7.  
  8.  
  9. NSMutableArray *arrMain=[NSMutableArray arrayWithObjects: cnfqty, cnftitle, cnfrate, nil];
  10.  
  11. finarray=[[NSMutableArray alloc]init];
  12. [finarray addObjectsFromArray:arrMain];
  13.    NSLog(@"%@",finarray);
  14.  
  15.  
  16. }
  17.  
  18. - (void)viewDidUnload
  19. {
  20. [super viewDidUnload];
  21. // Release any retained subviews of the main view.
  22. // e.g. self.myOutlet = nil;
  23. }
  24.  
  25. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  26.  {
  27. return (interfaceOrientation == UIInterfaceOrientationPortrait);
  28.  }
  29.  
  30.  #pragma mark - Table view data source
  31.  
  32.  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  33.  {
  34.  
  35. // Return the number of sections.
  36. return 1;
  37. }
  38.  
  39.  -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  40.  {
  41.  
  42. return 150.0;
  43.  
  44.  }
  45.  
  46.  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  47.  {
  48.  // Return the number of rows in the section.
  49. return ( [finarray count] / 3 );
  50. }
  51.  
  52.  
  53.  - (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
  54.  
  55. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  56.  
  57. UILabel *tempLabel;
  58. //UIImage *tempImage;
  59.  
  60. /* Create UI elements - Customize as you want your text to appear */
  61.  
  62. CGRect myFirstLabel = CGRectMake (65, 10, 200, 15);
  63. CGRect mySecondLabel = CGRectMake (65, 25, 200, 15);
  64. CGRect myThirdLabel = CGRectMake (65, 40, 200, 15);
  65.  //  CGRect myImage = CGRectMake (10, 10, 50, 50);
  66.  
  67. //Initialize first label
  68. tempLabel = [[UILabel alloc] initWithFrame: myFirstLabel];
  69. tempLabel.tag = 1;
  70. tempLabel.font = [UIFont boldSystemFontOfSize:12];
  71. tempLabel.textColor = [UIColor lightGrayColor];
  72. [cell.contentView addSubview: tempLabel];
  73.  
  74. //Initialize second label
  75. tempLabel = [[UILabel alloc] initWithFrame: mySecondLabel];
  76. tempLabel.tag = 2;
  77. tempLabel.font = [UIFont boldSystemFontOfSize:12];
  78. tempLabel.textColor = [UIColor lightGrayColor];
  79. [cell.contentView addSubview: tempLabel];
  80.  
  81. //Initialize third label
  82. tempLabel = [[UILabel alloc] initWithFrame: myThirdLabel];
  83. tempLabel.tag = 3;
  84. tempLabel.font = [UIFont boldSystemFontOfSize:12];
  85. tempLabel.textColor = [UIColor lightGrayColor];
  86. [cell.contentView addSubview: tempLabel];
  87.  
  88. //Initialize your picture
  89. //imgTemp = [[UIImageView alloc] initWithFrame: myImage];
  90. //imgTemp.tag = 4;
  91. //[cell.contentView addSubview: tempImage];
  92.  
  93. return cell;
  94.  }
  95.  
  96.  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  97. {
  98. static NSString *CellIdentifier = @"aCell";
  99.  
  100. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  101.  
  102. if (cell == nil) {
  103.     cell = [self getCellContentView: CellIdentifier];
  104. }
  105.  
  106. //This will create the actual UI elements
  107. UILabel *tempLabel1 = (UILabel *)[cell viewWithTag: 1];
  108. UILabel *tempLabel2 = (UILabel *)[cell viewWithTag: 2];
  109. UILabel *tempLabel3 = (UILabel *)[cell viewWithTag: 3];
  110. //UIImageView *tempImage = (UIImageView *)[cell viewWithTag: 4];
  111.  
  112. // Populate the labels
  113. NSString *firstText = [NSString stringWithString: [finarray objectAtIndex: 3*(indexPath.row)]];
  114. NSString *secondText = [NSString stringWithString: [finarray objectAtIndex: 3*(indexPath.row) + 1]];
  115. NSString *thirdText = [NSString stringWithString: [finarray objectAtIndex: 3*(indexPath.row) + 2]];
  116.  
  117. // Populate the picture
  118. //UIImage *picture = [[UIImage alloc] initWithData:theObjectToPutInCell.picture];
  119.  
  120. tempLabel1.text = firstText;
  121. tempLabel2.text = secondText;
  122. tempLabel3.text = thirdText;
  123.  
  124.  // tempImage.image = picture;
  125.  
  126. return cell;  
  127.  
  128.  
  129. }
  130. }
  131.  
  132. @end
  133.        
  134. // Cell appearence editing
  135. - (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier {
  136.  
  137.     UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  138.  
  139.     UILabel *tempLabel;
  140.     UIImage *tempImage;
  141.  
  142.     /* Create UI elements - Customize as you want your text to appear */
  143.  
  144.     CGRect myFirstLabel = CGRectMake (65, 10, 200, 15);
  145.     CGRect mySecondLabel = CGRectMake (65, 25, 200, 15);
  146.     CGRect myThirdLabel = CGRectMake (65, 40, 200, 15);
  147.     CGRect myImage = CGRectMake (10, 10, 50, 50);
  148.  
  149.     //Initialize first label
  150.     tempLabel = [[UILabel alloc] initWithFrame: myFirstLabel];
  151.     tempLabel.tag = 1;
  152.     tempLabel.font = [UIFont boldSystemFontOfSize:12];
  153.     tempLabel.textColor = [UIColor lightGrayColor];
  154.     [cell.contentView addSubview: tempLabel];
  155.  
  156.     //Initialize second label
  157.     tempLabel = [[UILabel alloc] initWithFrame: mySecondLabel];
  158.     tempLabel.tag = 2;
  159.     tempLabel.font = [UIFont boldSystemFontOfSize:12];
  160.     tempLabel.textColor = [UIColor lightGrayColor];
  161.     [cell.contentView addSubview: tempLabel];
  162.  
  163.     //Initialize third label
  164.     tempLabel = [[UILabel alloc] initWithFrame: mySecondLabel];
  165.     tempLabel.tag = 3;
  166.     tempLabel.font = [UIFont boldSystemFontOfSize:12];
  167.     tempLabel.textColor = [UIColor lightGrayColor];
  168.     [cell.contentView addSubview: tempLabel];
  169.  
  170.     //Initialize your picture
  171.     imgTemp = [[UIImageView alloc] initWithFrame: myImage];
  172.     imgTemp.tag = 4;
  173.     [cell.contentView addSubview: tempImage];
  174.  
  175.     return cell;
  176. }
  177.        
  178. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  179. {
  180.  
  181.     static NSString *CellIdentifier = @"aCell";
  182.  
  183.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  184.  
  185.     if (cell == nil) {
  186.         cell = [self getCellContentView: CellIdentifier];
  187.     }
  188.  
  189.     //This will create the actual UI elements
  190.     UILabel *tempLabel1 = (UILabel *)[cell viewWithTag: 1];
  191.     UILabel *tempLabel2 = (UILabel *)[cell viewWithTag: 2];
  192.     UILabel *tempLabel3 = (UILabel *)[cell viewWithTag: 3];
  193.     UIImageView *tempImage = (UIImageView *)[cell viewWithTag: 4];
  194.  
  195.     // Populate the labels
  196.     NSString *firstText = [NSString stringWithString: [finarray stringAtIndex: 3*(indexPath.row)]];
  197.     NSString *secondText = [NSString stringWithString: [finarray stringAtIndex: 3*(indexPath.row) + 1]];
  198.     NSString *thirdText = [NSString stringWithString: [finarray stringAtIndex: 3*(indexPath.row) + 2]];
  199.  
  200.     // Populate the picture
  201.     UIImage *picture = [[UIImage alloc] initWithData:theObjectToPutInCell.picture];
  202.  
  203.     tempLabel1.text = firstText;
  204.     tempLabel2.text = secondText;
  205.     tempLabel3.text = thirdText;
  206.  
  207.     tempImage.image = picture;
  208.  
  209.     return cell;
  210.  
  211. }
  212.        
  213. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  214. {
  215.  
  216.     // Return the number of sections.
  217.     return 1;
  218. }
  219.  
  220. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  221. {
  222.  
  223.     // Return the number of rows in the section.
  224.     return [itemsData count];
  225. }
  226.  
  227. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  228. {
  229.    // static NSString *CellIdentifier = @"Cell";
  230.     NSString *CellIdentifier = [NSString stringWithFormat:@"%d", indexPath.row] ;
  231.     UILabel *lblTitle = nil;
  232.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  233.     if (cell == nil) {
  234.         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
  235.         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  236.         cell.selectionStyle = UITableViewCellSelectionStyleNone;
  237.  
  238.  
  239.  
  240.  
  241.         lblTitle =[[UILabel alloc]initWithFrame:CGRectMake(5, 15, 110, 44)];
  242.         lblTitle.backgroundColor = [UIColor clearColor];
  243.         lblTitle.textColor = [UIColor whiteColor];
  244.         lblTitle.font = [UIFont systemFontOfSize:11.0];
  245.         lblTitle.tag = 1;
  246.         lblTitle.numberOfLines = 0;
  247.  
  248.  
  249.         UILabel *lblType =[[UILabel alloc]initWithFrame:CGRectMake(125, 0, 75, 44)];
  250.         lblType.backgroundColor = [UIColor clearColor];
  251.         lblType.textColor = [UIColor whiteColor];
  252.         lblType.font = [UIFont systemFontOfSize:11.0];
  253.         lblType.tag = 2;
  254.  
  255.         UILabel *lblDate =[[UILabel alloc]initWithFrame:CGRectMake(200, 0, 60, 44)];
  256.         lblDate.backgroundColor = [UIColor clearColor];
  257.         lblDate.textColor = [UIColor whiteColor];
  258.         lblDate.font = [UIFont systemFontOfSize:11.0];
  259.         lblDate.tag = 3;
  260.  
  261.         UILabel *lblTime =[[UILabel alloc]initWithFrame:CGRectMake(265, 0, 50, 44)];
  262.         lblTime.backgroundColor = [UIColor clearColor];
  263.         lblTime.textColor = [UIColor whiteColor];
  264.         lblTime.font = [UIFont systemFontOfSize:11.0];
  265.         lblTime.tag = 4;
  266.  
  267.         [tableView beginUpdates];
  268.         [tableView endUpdates];
  269.         [cell.contentView addSubview:lblTitle];
  270.         [cell.contentView addSubview:lblType];
  271.         [cell.contentView addSubview:lblDate];
  272.         [cell.contentView addSubview:lblTime];
  273.  
  274.     }
  275.  
  276. NSString *text = [NSString stringWithFormat:@"%@,%@,%@",[[itemsData objectAtIndex:indexPath.row] objectForKey:@"address"],[[itemsData objectAtIndex:indexPath.row] objectForKey:@"title"],[[itemsData objectAtIndex:indexPath.row] objectForKey:@"zipcode"]];
  277.  
  278.  
  279.     CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
  280.  
  281.     CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeCharacterWrap];
  282.  
  283.     if (!lblTitle)
  284.         lblTitle = (UILabel*)[cell viewWithTag:1];
  285.  
  286.     [lblTitle setText:text];
  287.     [lblTitle setFrame:CGRectMake(CELL_CONTENT_MARGIN, CELL_CONTENT_MARGIN, CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), MAX(size.height, 44.0f))];
  288.  
  289.  
  290.     UILabel *lblType = (UILabel *) [cell.contentView viewWithTag:2];
  291.     lblType.text =[[itemsData objectAtIndex:indexPath.row] objectForKey:@"type"];
  292.  
  293.     UILabel *lblDate = (UILabel *) [cell.contentView viewWithTag:3];
  294.     lblDate.text =[[itemsData objectAtIndex:indexPath.row] objectForKey:@"date"];
  295.  
  296.     UILabel *lblTime = (UILabel *) [cell.contentView viewWithTag:4];
  297.     lblTime.text =[[itemsData objectAtIndex:indexPath.row] objectForKey:@"time"];
  298.  
  299.     return cell;
  300. }