Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BollywooD

macrumors 6502
Original poster
Apr 27, 2005
372
46
Hamburg
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?
 
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.
 
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....
 
Try reproducing it in a separate project, and if so, post that project. Might have something to do with selectsInsertedObjects
 
When I implement a controller object to Interface builder, i can now get the correct index returned...... but, now my tableView wont update?
 
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.
 
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:
 
I seem to recall that -selectedRow was sort of or officially deprecated in, I think, 10.3 in favor of -selectedRowIndexes.
 
I seem to recall that -selectedRow was sort of or officially deprecated in, I think, 10.3 in favor of -selectedRowIndexes.

selectedRowEnumerator went deprecated, but selectedRow is still valid.
 
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.
:)
 
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:
[subscriptionsArrayController rearrangeObjects];

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:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.