Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView problem with adding extra cell
    primarykey
    data
    text
    <p>First question on this site, although I have been around for a while behind the scenes. I have a problem that I have been racking my head on for the last two days and I hope someone can shed some light on it for me.</p> <p>I have a UITableView, which is loaded from a SQL database. It has 15 entries in it. I have inserted an extra cell at the beginning of the UITableView. This extra cell is for a UITextField and UIButton which adds an item into the database. </p> <p>When the view is loaded, the first cell with the custom objects shows fine, and the rest of the table is filled with items from the database and looks just how it should. However, when the UITableView is scrolled down so the first cell is out of view, then back up, it takes the value of the 11th row item and shows it over top the first cell.</p> <p>Here is my code:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)popTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; static NSInteger NameTag = 1; UITableViewCell *cell = [popTableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; CGRect frame; frame.origin.x =50; frame.origin.y =10; frame.size.height =22; frame.size.width =275; UILabel *nameLabel = [[UILabel alloc] initWithFrame:frame]; nameLabel.tag = NameTag; nameLabel.opaque = YES; nameLabel.textColor = [UIColor grayColor]; nameLabel.backgroundColor = [UIColor clearColor]; [cell.contentView addSubview:nameLabel]; [nameLabel release]; } int row = [indexPath row]; if (row == 0) { UIButton *buttonLeft = [UIButton buttonWithType:UIButtonTypeCustom]; [buttonLeft setFrame: CGRectMake( 205, 6, 40, 33)]; [buttonLeft addTarget:self action:@selector(addToList:) forControlEvents:UIControlEventTouchUpInside]; [cell addSubview:buttonLeft]; //No Alloc for txtField, it is built in IB [txtField setBorderStyle:UITextBorderStyleNone]; [txtField setFrame: CGRectMake( 17, 12, 180, 23)]; txtField.backgroundColor = [UIColor clearColor]; [txtField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged]; txtField.clearButtonMode = UITextFieldViewModeAlways; }else{ UILabel * nameLabel = (UILabel *) [cell.contentView viewWithTag:NameTag]; Add *theObj = [self.theArray objectAtIndex:indexPath.row - 1]; [nameLabel setText:theObj.itemName]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; UIImageView *imageView = [cell viewWithTag:kTagCellImageView]; if (imageView == nil) { imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10.0, 10.0, 13.0, 25.0)]; imageView.backgroundColor = [UIColor clearColor]; imageView.tag = kTagCellImageView; [cell.contentView addSubview:imageView]; } if([theObj.itemName isEqualToString:@"First Street"]){ imageView.frame = CGRectMake(14,10,13,25); [imageView setImage:[UIImage imageNamed:@"firststreet"]]; } else if([theObj.itemName isEqualToString:@"Second Street"]){ imageView.frame = CGRectMake(8,12,29,20); [imageView setImage:[UIImage imageNamed:@"second"]]; } else if([theObj.itemName isEqualToString:@"Main Street"]){ imageView.frame = CGRectMake(15,10,13,25); [imageView setImage:[UIImage imageNamed:@"mainstreet"]]; } else{ imageView.frame = CGRectMake(8,8,25,25); [imageView setImage:[UIImage imageNamed:@"iconcustom"]]; } NSLog(@"%@",itemName); NSLog(@"%@",itemCategory); } return cell; } </code></pre> <p>Also here is my cellForRow:</p> <pre><code>- (NSInteger)tableView:(UITableView *)popTableView numberOfRowsInSection:(NSInteger)section { return [self.theArray count] + 1; //Add Extra cell to beginning </code></pre> <p>}</p> <p>Any ideas would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload