Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray Element lost when displaying in NSTableView is called
    text
    copied!<p>I was trying to display the contents of an array into a table view. The table view has single column. My class is <strong>RKCandidate</strong> which is a subclass of <strong>NSWindowController</strong>. RKCandidate is also the Owner of the 'nib' file In IB I have selected the File's Owner as the dataSource of the tableview.</p> <p>There are the methods I'm using to update the tableview,</p> <pre><code>- (id) initWithClient:(TextInputController *) client { self = [super initWithWindowNibName:@"RKCandidate"]; if (self != nil) { _client = client; } return self; } - (void) dealloc { [optionsArray release]; [super dealloc]; } - (void) updateCandidate { NSLog(@"updateCandidate Called.\n"); optionsArray = [_client composedStringArray:self]; [candidateOptions reloadData]; NSLog(@"Retain Count of OptionsArray: %i\n",[optionsArray retainCount]); NSLog(@"Object Count of OptionsArray: %i\n",[optionsArray count]); NSLog(@"Address of Object: %i\n",[optionsArray objectAtIndex:0]); NSLog(@"Object: %@\n",[optionsArray objectAtIndex:0]); //NSString *benChar = [optionsArray objectAtIndex:0]; //NSLog(@"Object Retain Count: %@i\n",[benChar retainCount]); } #pragma mark TableView Data Source Methods #pragma mark - - (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView { NSLog(@"Retain Count of OptionsArray: %i\n",[optionsArray retainCount]); NSLog(@"Object Count of OptionsArray: %i\n",[optionsArray count]); NSLog(@"Address of Object: %i\n",[optionsArray objectAtIndex:0]); NSLog(@"Object: %@\n",[optionsArray objectAtIndex:0]); //NSLog(@"Object Retain Count: %@i\n",[[optionsArray objectAtIndex:0] retainCount]); return [optionsArray count]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { NSLog(@"Retain Count of OptionsArray: %i\n",[optionsArray retainCount]); NSLog(@"Object Count of OptionsArray: %i\n",[optionsArray count]); NSLog(@"Address of Object: %i\n",[optionsArray objectAtIndex:0]); NSLog(@"Object: %@\n",[optionsArray objectAtIndex:0]); //NSLog(@"Object Retain Count: %@i\n",[[optionsArray objectAtIndex:0] retainCount]); return [optionsArray objectAtIndex:rowIndex]; } </code></pre> <p>The <strong>optionsArray</strong> is updated by a simple method from client the method is as follows,</p> <pre><code>-(NSMutableArray *) composedStringArray:(id)sender { NSLog(@"returning composedStringArray.\n"); return convertBufferArray; } </code></pre> <p><strong>convertBufferArray</strong> is a mutable array.</p> <p>When the <strong>updateCandidate</strong> method is called for the first time. It works nicely. But problem starts when I call it second time after updating the <strong>convertBufferArray</strong> array inside the client.</p> <p>When the <strong>updateCandidate</strong> method is called from the first time the Console log is as follows:</p> <pre><code>2010-11-20 09:03:35.385 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:35.385 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:35.386 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:35.386 Input Method Tester[7225:a0f] Object: ∆ 2010-11-20 09:03:35.392 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:35.392 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:35.393 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:35.393 Input Method Tester[7225:a0f] Object: ∆ 2010-11-20 09:03:35.397 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:35.397 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:35.398 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:35.399 Input Method Tester[7225:a0f] Object: ∆ </code></pre> <p>The table view displays the content of the array.</p> <p>But when I just add another letter to the <strong>Object</strong> string, some how, the string gets replaced with an empty string when the - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex is called. The log is as follows.</p> <pre><code>2010-11-20 09:03:38.349 Input Method Tester[7225:a0f] returning composedStringArray. 2010-11-20 09:03:38.350 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:38.351 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:38.352 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:38.353 Input Method Tester[7225:a0f] Object: ∆ç 2010-11-20 09:03:38.354 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:38.354 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:38.354 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:38.355 Input Method Tester[7225:a0f] Object: ∆ç 2010-11-20 09:03:38.358 Input Method Tester[7225:a0f] Retain Count of OptionsArray: 1 2010-11-20 09:03:38.358 Input Method Tester[7225:a0f] Object Count of OptionsArray: 1 2010-11-20 09:03:38.359 Input Method Tester[7225:a0f] Address of Object: 1372384 2010-11-20 09:03:38.359 Input Method Tester[7225:a0f] Object: </code></pre> <p>As you can see in the list line of the above log the string is empty. The tableView become empty.</p> <p>Is there anything wrong I'm doing? I've tried putting the release and retaining the <strong>optionsArray</strong> but the result is the same. I also tried to copy the content of the <strong>composedBufferArray</strong> into the the <strong>optionsArray</strong>. I tried putting</p> <pre><code>optionsArray = [_client composedStringArray:self]; </code></pre> <p>into the init method. The result is the same for all the cases. </p> <p>Please help. I couldn't solve this problem for last two days. Please help.</p> <p>Sorry I couldn't post a image or a link as I'm totally new in Stack Overflow.</p> <p>Regards,</p> <p>Raiyan</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