CopyPastor

Detecting plagiarism made easy.

Score: 0.7696006894111633; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2015-04-21
by Sanjay Mohnani

Original Post

Original - Posted on 2011-11-10
by jbat100



            
Present in both answers; Present only in the new answer; Present only in the old answer;

As you are using reusable cells, like

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; UITextField *txtField ; if (cell ==nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; txtField = [[UITextField alloc]initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/3 + 40, 2, [UIScreen mainScreen].bounds.size.width/2, cell.layer.frame.size.height -5)]; [self setUpCell:cell withIndexPath:indexPath withTextField:txtField]; }
[self UpdateCell:cell withIndexPath:indexPath withTextField:txtField]; return cell; }
`UITableView` uses the concept of reusable cell to achieve maximum performance by reducing the memory consumption, and to exploit this feature of reusing cells you can use the above `UITableView's` API's to achieve that.
But before using any feature it's very important to understand the working and the usage of any feature.
In your above implementation of `tableView: cellForRowAtIndexPath:` method, you have used the concept of cell reusability.
If the cells doesn't exist and are created for the first time, than they are allocated(every subview is created and added on the content view of the cell), customized and initialized with the data from the data source of the respective index path.
But in case the cells are reused(as they were already created for any other index path), there subviews exist with the data already filled for the previous index path for which it was created.
Now there are two things we can do to use already created cell for the current index path,
1) if the cells contain subview with data then remove the subviews and recreate the new ones, customize and populate them with the data.
2) rather than releasing the previous subviews and creating new ones, refill the data for the data model of the corresponding index path.
**In your case,** if the cell is being created for any index path, than the text filed for it is also created and if it's reused than the new text field is not created and it's being reused from the previously created cell **thus the issue of the placeholder text not matching with the left text**.
**So, in order to solve your problem** I think you should either create the textfield when the cell is created and if the cells are reused than refill the data in the text filed from the data source of the corresponding index path.
I'll try and break it down (example from [documention][1])
/* * The cellForRowAtIndexPath takes for argument the tableView (so if the same object * is delegate for several tableViews it can identify which one is asking for a cell), * and an indexPath which determines which row and section the cell is returned for. */ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { /* * This is an important bit, it asks the table view if it has any available cells * already created which it is not using (if they are offScreen), so that it can * reuse them (saving the time of alloc/init/load from xib a new cell ). * The identifier is there to differentiate between different types of cells * (you can display different types of cells in the same table view) */ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; /* * If the cell is nil it means no cell was available for reuse and that we should * create a new one. */ if (cell == nil) {
/* * Actually create a new cell (with an identifier so that it can be dequeued). */ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyIdentifier"] autorelease]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } /* * Now that we have a cell we can configure it to display the data corresponding to * this row/section */
NSDictionary *item = (NSDictionary *)[self.content objectAtIndex:indexPath.row]; cell.textLabel.text = [item objectForKey:@"mainTitleKey"]; cell.detailTextLabel.text = [item objectForKey:@"secondaryTitleKey"]; NSString *path = [[NSBundle mainBundle] pathForResource:[item objectForKey:@"imageKey"] ofType:@"png"]; UIImage *theImage = [UIImage imageWithContentsOfFile:path]; cell.imageView.image = theImage; /* Now that the cell is configured we return it to the table view so that it can display it */ return cell; }
This is a `DataSource` method so it will be called on whichever object has declared itself as the `DataSource` of the `UITableView`. It is called when the table view actually needs to display the cell onscreen, based on the number of rows and sections (which you specify in other DataSource methods).
[1]: http://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1

        
Present in both answers; Present only in the new answer; Present only in the old answer;