Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView with text and images: mixed up in dequeueReusableCellWithIdentifier
    text
    copied!<p>I have a small problem, which seems to be really classic (mixed up cells when reused by dequeueReusableCellWithIdentifier) but I have already looked at similar questions and can't find an answer.</p> <p>So, classic context: I have a <code>UITableView</code> with protype cells in the storyboard, one with an image (asynchronously fetched) and one with a UITextView.</p> <p>Let's focus on the text cells as I get problems on both and so we know the network is not the cause. </p> <p>When I scoll down and up again, cells get mixed up. I think it is because I set the text value according to my data inside the <code>cellForRowAtIndexPath</code> function but I'm not sure.</p> <p>Here are my cells in my example:</p> <pre><code>--------------- | 1. "TEXT1" | --------------- | | | 2. IMAGE2 | | | --------------- | 3. "TEXT3" | --------------- | 4. "TEXT4" | --------------- | | | 5. IMAGE5 | | | --------------- </code></pre> <p>I scroll all the way down, everything is fine. When I bounce at bottom, cells 3 and 4 are reloaded (I put a NSLog in <code>cellForRowAtIndexPath</code>function). First cell 4 is reloaded, then cell 3 (according to the log). The problem is, cells 3 and 4 both end up with "TEXT3" as value ! I mean, if I <code>NSLog</code> the value I give to the UITextField.text in the function, they don't have the same text value, but on the simulator's screen, they have.. ?</p> <p>Here is my code:</p> <pre class="lang-c prettyprint-override"><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Getting data for row from indexPath Data *data = [self.dataArray objectAtIndex:indexPath.row]; NSString *cellIdentifier = [NSString stringWithFormat:@""]; if (data.type == 1) { // Text type cellIdentifier = @"TextCell"; } else if (data.type == 2){ cellIdentifier = @"PhotoCell"; } UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; // Getting various cell elements if (data.type == 1) { // Text is 1000 UITextView *textView = (UITextView *)[tableView viewWithTag:1000]; textView.text = data.text; } else if (data.type == 2){ //STUFF FOR PHOTO TYPE OF DATA } return cell; } </code></pre> <p>By the way, it can be useful to say that I get this error in the simulator on iOS6 but not on iOS7 (but maybe that's just different memory management..)</p> <p>Thanks a lot for your help!</p>
 

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