NSTableView selectedRow

Discussion in 'Mac Programming' started by BollywooD, Jan 4, 2010.

  1. BollywooD macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #1
    I am having trouble getting the selected row from my tableView, everything is connected fine (I think), as everything else works as it should......

    the tableView is connected as an Outlet to File's Owner
    and the content is bound to arrangedObjects on my ArrayController.

    when I call:
    Code:
    [myTableView selectedRow];
    in the following named method, attached to an NSButton
    Code:
    - (IBAction)update:(id)sender
    it always returns the last object that was added, and not the currently selected one?

    Oh, I are using custom cells, if that may have any effect.(not sure why it would....)

    this is driving me crazy.....


    is there something else I should be doing?
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Since you're using an array controller, you should use it for obtaining information about the selection instead of the table view. Look up NSArrayController in Xcode's documentation and you'll see a section for Managing Selections.
     
  3. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #3
    I am now using this:
    Code:
    int x = [myArrayController selectionIndex];
    and I am getting exactly the same behaviour as before?
    x is always returned as the last added object, and not the current selection....
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Try reproducing it in a separate project, and if so, post that project. Might have something to do with selectsInsertedObjects
     
  5. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #5
    When I implement a controller object to Interface builder, i can now get the correct index returned...... but, now my tableView wont update?
     
  6. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    I sense something funky is going on.

    Unless you're trying to customize your table view extensively, you really don't even need an outlet to it if you're just using it for general data via your array controller. All you need is the outlet to the array controller created in the nib, then you can manage displaying of the table through the array controller. You can add objects directly to it, instead of your array, and the table will update directly.
     
  7. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #7
    its driving me crazy.....


    all im doing is customizing the cells like in this sample here

    ive been working on this ALL day
    :mad::confused:
     
  8. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #8
    I seem to recall that -selectedRow was sort of or officially deprecated in, I think, 10.3 in favor of -selectedRowIndexes.
     
  9. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #9
    selectedRowEnumerator went deprecated, but selectedRow is still valid.
     
  10. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #10
    so, Ive chosen to use an Object controller. but the TableView won't reload when I add entries to the nsarraycontroller, it does reload, when current entries are modified however.....

    so I was wondering if maybe i am adding objects in a non KVO way?

    this is how my tableview is initialised, in my init method:
    Code:
    int i = 0;
    		NSMutableArray *subArray = [[NSMutableArray new] autorelease];
    		for (NSDictionary *child in subscriptionsArray)
    		{
    			NSDictionary* subscriptionsDictionary = [subscriptionsArray objectAtIndex:i];
    			SubscriptionInfo* subscriptionInfo   = [[[SubscriptionInfo alloc] initWithInfoDictionary: subscriptionsDictionary] autorelease];
    			
    			[subscriptions addObject: subscriptionInfo];
    			
    			[(NSMutableArray *)subArray addObject:subscriptionsDictionary];
    			
    			subscriptionArray = [subArray retain];
    			i++;
    		}
    which works great.

    and this is how im adding objects:
    Code:
    NSDictionary *output;
    	output = [NSDictionary dictionaryWithObjectsAndKeys:title, @"feedNameKey", 
    														urlString, @"feedURLKey",
    														defaultValue, @"feedUpdatedKey", nil];
    	
    	SubscriptionInfo* subscriptionInfo   = [[[SubscriptionInfo alloc] initWithInfoDictionary: output] autorelease];
    	
    	[subscriptionsArrayController addObject: subscriptionInfo];
    Am I doing something wrong?


    any help is appreciated,
    cheers in advance.
    :)
     
  11. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #11
    So I am now adding objects to the arraycontroller like so:
    Code:
    SubscriptionInfo* subscriptionInfo   = [[[SubscriptionInfo alloc] initWithInfoDictionary: output] autorelease];
    	
    	[subscriptionsArrayController insertObject:subscriptionInfo atIndex:[subscriptionsArrayController count]];
    but they wont show in the TableView until i update an object through an IBOutlet button method.

    I tried calling:
    to refresh the view, but its not working.


    What im asking is: how can I manually refresh the TableView/ArrayController.


    I also tried:
    Code:
    [myTableView reloadData
    :confused:
     
  12. BollywooD thread starter macrumors 6502

    BollywooD

    Joined:
    Apr 27, 2005
    Location:
    Surfers Paradise
    #13
    I ended up scrapping the NSArrayController....

    too many headaches.:eek:
     

Share This Page