Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Getting string from MutableArray?

ChrisYatesChrisYates Posts: 325Registered Users
I'm trying to get the stringValue from a NSMutableArray from a TableView on user selection but am struggling. The NSLog is showing null so I know I'm doing something wrong, here's the code I'm using:

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
{

NSString *editedValue = [[[notesTable selectedCell] stringValue] copy];

NSLog(@\"my ns string = %@\", editedValue);

[textView.string isEqualToString:editedValue];

}
Post edited by ChrisYates on

Replies

  • nestochinestochi Posts: 44Registered Users
    not sure what you are trying to do (editing or showing some text after cell selection).

    If you have an array representing the model, you should get it from there, not from the cell. (it's a guess, not sure what you need).

    Just get the selected row, and with that row number, get your data from your array.


    row = [notesTable selectedRow];
    id somethingFromArray = [array objectAtIndex:row]


    if you're trying to get the text the user edited in a tableview cell, you should use


    - (void) textDidEndEditing: (NSNotification *) notification
  • ChrisYatesChrisYates Posts: 325Registered Users
    Thanks nestochi for the reply.

    Basically I have an NSTextView and a save button. The user can enter into the textView and save the data which is then displayed in a table.

    What I'm trying to do is when the user clicks on a tableview cell the text is displayed back in the NSTextView?

    The user can then edit the text as necessary and re-save it to the original tableview cell?
  • nestochinestochi Posts: 44Registered Users
    ok, then you are in the right direction. But you should not get the text from the table view, you should get it from the model (your array).


    something like this:

    - (void)tableViewSelectionDidChange:(NSNotification *)aNotification
    {
    int selectedRow = [notesTable selectedRow];

    // here i am supposing your array contains strings.
    NSString * somethingFromArray = [array objectAtIndex:selectedRow]
    // Set the text in the textview
    [[[messageField textStorage] mutableString] setString:somethingFromArray];
    }

  • ChrisYatesChrisYates Posts: 325Registered Users
    Thanks nestochi, I realised yesterday that I was using a Dictionary so that was the reason it wasn't working. Finally resolved it in the end though...seemed to take forever!
Sign In or Register to comment.