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 10-16-2010, 10:39 PM   #1 (permalink)
Registered Member
 
Whitehk's Avatar
 
Join Date: Feb 2010
Posts: 119
Whitehk is on a distinguished road
Default Reload a UITableView without deleting previously entered data?

Hello. I have a navigation based application, and the UITableView is populated with custom cells I've created in Interface Builder. Each cell has a UILabel and a UITextField in it. When the tableView is in editing mode, you can edit the textfield. When it isn't, you can't edit it, and when the user taps on it the cell, it goes to a separate view controller. When the user clicks the add cell button at the top, it adds a new cell. However, when I do this, in order for the new cell to show up, I have to call [tableView reloadData]. Which erases what the user inputted into the textfield. I want to be able to reload the data without it doing this. Here is some of the code:

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSString *CellIdentifier = @"CustomCell";
	
	CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
	
	if (cell == nil) {
		NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil];
		
		for (id currentObject in topLevelObjects) {
			if([currentObject isKindOfClass:[UITableViewCell class]]) {
				cell = (CustomCell *) currentObject;
				break;
			}
		}
	}
	
	return cell;
}

- (void)addRow:(id)sender; {
	if(numberOfViewsAndRows < 10) {
		[self setEditing:YES animated:YES];
		
		CustomCell *theCell = (CustomCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
		
		// allocate a view and add to the view array as a dictionary item
		theCell.textField.text = [NSString stringWithFormat:@"Untitled"];
		TheViewController *theViewController = [[TheViewController alloc] init];
		ptheViewController.title = [NSString stringWithFormat:@"%@", theCell.textField.text];
		[views addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"Untitled", @"title", theViewController, @"controller", nil]];
		[theViewController release];
	
		[self.tableView reloadData];
		numberOfViewsAndRows += 1;
	} else {
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Too Many Cells" message:@"You can only have up to 10." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
			[alert show];
			[alert release];
	}
}
Here is a video showing what I'm trying to explain:
YouTube - UITableView Problem
Whitehk is offline   Reply With Quote
Reply

Bookmarks

Tags
indexpath, reload data, reusable cell, uitableview, uitableviewcell

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: 340
8 members and 332 guests
Desert Diva, dre, hain, HemiMG, mottdog, oceanlablight, schmallegory
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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