OK heres my problem , i have a UITableView with about oh say 20 rows, since all the rows cant fit on the screen at once they have to load pending upon wat row the user is trying to display. My problem is for some reason my first row and last row are interchanging values , the title of the first row will change to the title in the second row and on and on and on. I had this problem before and i thought all you had to do was add a tag to each UI element in the row and this fixed it but now idk why its not working ill post some of the code i hope it can help you guys realize whats going on with my program.
//heres my .h file
Code:
//MyTableViewController.h file
#define firstLabelTag 1
#define secondLabelTag 2
#define thirdLabelTag 3
@interface MyTableViewController : UITableViewController {
UITableView *browseMenuTableView;
}
@property (nonatomic,retain) UITableView *browseMenuTableView;
@end
heres the implementation file
Code:
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
return tableViewCount;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
NSInteger row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
CGRect cellFrame = CGRectMake(0,0,300,65);//creates a rectangle
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:CellIdentifier] autorelease];
if(browse.overallCount>browse.count&&row==tableViewCount-1){
UILabel *cellLabel =[[UILabel alloc]initWithFrame:CGRectMake(80, 10, 150, 20)];
cellLabel.tag = moreButtonTag;
cellLabel.font =[UIFont boldSystemFontOfSize:16];
cellLabel.textAlignment = UITextAlignmentLeft;
cellLabel.backgroundColor =[UIColor colorWithWhite:1 alpha:0];
[cell.contentView addSubview:cellLabel];
[cellLabel release];
}
else{
UILabel *InventoryNumValue = [[UILabel alloc]initWithFrame:CGRectMake(50, 5, 200, 15)];
InventoryNumValue.tag = objectTitleTag;
InventoryNumValue.font = [UIFont boldSystemFontOfSize:12];
InventoryNumValue.textAlignment = UITextAlignmentLeft;
InventoryNumValue.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
[cell.contentView addSubview:InventoryNumValue];
[InventoryNumValue release];
UILabel *objectTitleValue = [[UILabel alloc]initWithFrame:CGRectMake(50, 25, 200,15)];
objectTitleValue.tag = inventoryNumberTag;
objectTitleValue.font = [UIFont systemFontOfSize:12];
objectTitleValue.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
objectTitleValue.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:objectTitleValue];
[objectTitleValue release];
}
}
if(browse.overallCount>browse.count&&row==browse.count-1){
UILabel *label = (UILabel *)[cell.contentView viewWithTag:moreButtonTag];
[label setText:[title objectAtIndex:row]];
return cell;
[label release];
}
else{
UILabel *inventoryLabel = (UILabel *)[cell.contentView viewWithTag:objectTitleTag];
inventoryLabel.text = [inventory objectAtIndex:row];
inventoryLabel.textAlignment=UITextAlignmentLeft;
UILabel *objectTitleLabel = (UILabel *)[cell.contentView viewWithTag:inventoryNumberTag];
objectTitleLabel.text=[title objectAtIndex:row];
objectTitleLabel.textAlignment=UITextAlignmentLeft;
UIImage *theImage= [[UIImage alloc]initWithData:[image objectAtIndex:row]];
cell.imageView.contentMode = UIViewContentModeScaleToFill;
cell.imageView.contentMode=UIViewContentModeLeft;
cell.imageView.image = theImage;
[theImage release];
return cell;
[cell release];
[inventoryLabel release];
[objectTitleLabel release];
}
}