Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-05-2010, 12:42 PM   #1 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default UITableView rows getting mixed up

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];
	}
}
Esko2300 is offline   Reply With Quote
Old 10-11-2010, 03:20 AM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Location: Dhaka
Posts: 5
agentBangla is on a distinguished road
Send a message via Skype™ to agentBangla
Default Update

Did you find the solution... I am eager to have that please.
agentBangla is offline   Reply With Quote
Old 10-13-2010, 08:34 AM   #3 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default

ya you just have to set the tag of each row to a certian value and then it wont get mixed up. Im not 100% sure this is correct since i fixed it many months ago but just try it out it should work.
Esko2300 is offline   Reply With Quote
Old 10-15-2010, 08:56 AM   #4 (permalink)
Awesome
 
Esko2300's Avatar
 
Join Date: Jun 2009
Location: New York, N.Y.
Posts: 389
Esko2300 is on a distinguished road
Default

I remember now what you have to do is create a variable, in my example this variable is called someVariable, set someVariable = 0 then for every cell you will increment someVariable this will give every row its own identifier and the rows shouldent get mixed up

Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
    
    static NSString *CellIdentifier = @"Cell";    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
		//set up your cell
      cell.tag = someVariable;
      someVariable++;
    }
}
Esko2300 is offline   Reply With Quote
Reply

Bookmarks

Tags
row, uitablecell, uitableview, uitableviewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 316
10 members and 306 guests
alexP, arash5500, gordo26, HemiMG, mediaspree, nobstudio, Objective Zero, Sloshmonster, stanny, Touchmint
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0