Re: NSTableview datasource issues

2009-12-24 Thread aronisoft
Actually the reloadData and datasource issues with NSTableView are reported 
often. Please try to google or bing these issues and you will be amazed on 
how many complaints are out there.


Xcode could for example flag the datasource method where I had capitalized 
objectValueForTableColumn, either by pointing out that the method does not 
exist in interface or that I need to implement datasource methods correctly.


Unfortunately, sometimes one may not share all the code for confidentiality 
reasons. As you said, one bites the bullet, rewrites the code, and moves on.
Thanks again.






-Original Message-
From: Greg Guerin [mailto:glgue...@amug.org]
Sent: Thursday, December 24, 2009 12:21 PM
To: 'list-cocoa-dev'
Subject: Re: NSTableview datasource issues

 ... The issue is that reloadData was not launching datasource  methods, 
 regardless. ... My concern though: how come Xcode does not flag issues with 
  datasource? What is so strange is that [segmentTableView  editColumn:k 
 row:i withEvent:nil select:YES] was launching the  datasource methods, 
 whereas reloadData was not.What would Xcode do, debug the code by itself?If 
 reloadData was the actual cause of the bug, then why isn't this problem 
 reported more often? Surely, you're not the only one using reloadData.There 
 was obviously some kind of bug in the code or in its connections to other 
 things. Finding out exactly what that bug is would require the full source 
 project of the malfunctioning program. If you haven't saved that, then the 
 information is lost forever. If you have saved it, then send it in a bug 
 report to Apple. You can also post the zipped project somewhere like 
 pastebin.com and post the URL to the list. Anyone who's interested can then 
 attack the problem.Every programmer eventually creates code that they 
 themselves can't debug. Sometimes the bug isn't found despite considerable 
 effort, and a rewrite ensues. Sometimes another programmer finds the bug, but 
 I've never seen that happen without the source. Occasionally the bug is 
 eventually found by its creator, and with luck, it's accompanied by a 
 profound feeling of revelation, even epiphany. One doesn't always have the 
 time, though, so sometimes one must rewrite and move on. -- 
 GG___Cocoa-dev mailing list 
 (Cocoa-dev@lists.apple.com)Please do not post admin requests or moderator 
 comments to the list.Contact the moderators at 
 cocoa-dev-admins(at)lists.apple.comHelp/Unsubscribe/Update your 
 Subscription:http://lists.apple.com/mailman/options/cocoa-dev/aronisoft%40afroamerica.netThis
  email sent to aronis...@afroamerica.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTableview datasource issues

2009-12-23 Thread aronisoft
Greg,
Alexander.




I finally resolved the issue. I simply deleted and completely rewrote this 
particular controller as I could not figure out what the problem was. My 
application is now running without a hitch.


Greg, thanks for your proposed approach (by the way the cap was my error, but 
not the reason for datasource issues). The issue is that reloadData was not 
launching datasource methods, regardless.


Alexander, thanks for your advises about the possible leaks. I will take this 
into account as I analyze and optimize the entire code before UAT.


I appreciate all your help. My concern though: how come Xcode does not flag 
issues with datasource? What is so strange is that [segmentTableView 
editColumn:k row:i withEvent:nil select:YES] was launching the datasource 
methods, whereas reloadData was not.


Happy Holidays!




-Original Message-
From: Greg Guerin [mailto:glgue...@amug.org]
Sent: Sunday, December 20, 2009 09:13 PM
To: 'list-cocoa-dev'
Subject: Re: NSTableview datasource issues

 I understand your proposition. For some reason, the spaces are  stripped off 
 by the e-mail system, but you got it right.Did your email system also 
 capitalize ObjectValueForTableColumn? Actually, segmentDict contains the 
 copy of a global dictionary  created by the method [[MyDocument 
 getSectorSegmentData:(id)  sender]  mutableCopy]. Unfortunately i cannot 
 give here all the  code. Also, when I print the datasource and delegate for 
  segmentTableView, it is clear that it is not nil: the log shows  
 SelectorController, which is what it should be. My major puzzle is that all 
 other TableView in the application  using different datasources get loaded. 
 Cleaning all targets does  not change anything. Brief, the major problem is 
 this: the datasource methods do not get  called. Datasource is not nil at 
 run time, no error in the code. The  ArrayController is not empty, the code 
 looks fine. I will go back and review for the thousandth time the code 
 from  scratch and all the bindings, but up to now, I can't figure out  what 
 is wrong.Maybe you can add some assertions in your code. For example, given 
 the way segmentDict is used, it strongly suggests your design is effectively 
 a singleton. That is, there must only be a single instance of 
 SelectorController created and init'ed.The other thing that occurred to me is 
 if an instance of SelectorController is recreated by the nib, and another 
 instance is created in your code, then the instance you see with valid 
 datasource and delegate may not be the instance that the nib is using. One 
 instance may not be getting completely initialized.As a last resort, try 
 stripping classes, xibs, etc. in order to produce a simplified test case that 
 still exhibits the problem. In the process of simplifying, sometimes you do 
 something that causes the problem to go away. Tracking down the change that 
 causes things to work then leads to identifying the cause of the problem. 
 Even if the simplified case still has the problem, you still have something 
 that others can run and help debug. -- 
 GG___Cocoa-dev mailing list 
 (Cocoa-dev@lists.apple.com)Please do not post admin requests or moderator 
 comments to the list.Contact the moderators at 
 cocoa-dev-admins(at)lists.apple.comHelp/Unsubscribe/Update your 
 Subscription:http://lists.apple.com/mailman/options/cocoa-dev/aronisoft%40afroamerica.netThis
  email sent to aronis...@afroamerica.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: NSTableview datasource issues

2009-12-20 Thread aronisoft
Alexander,
Thanks for your help.
Yes, I set the breakpoint on the data source methods? The datasource methods 
are not reached at all.
I did not give you all the methods in my code (it is too lengthy). segmentDict 
is a global variable because I need it somewhere else.


segmentIndustryData is populated with the method [self insertObject: s 
inSectorDataAtIndex:(int)i] implemented as follows:


-(void) insertObject:(segmentIndustry *) s inSectorDataAtIndex:(int)index
{

//Add the inverse of this operation to the undo stack
NSUndoManager *undo = [[segmentTableView window] undoManager];
[[undo prepareWithInvocationTarget:self] 
removeObjectFromSectorDataAtIndex:index];
if (![undo isUndoing]){
[undo setActionName:@Insert Stock];
}
//Add the stock to Array
[self startObservingSelector:s];
[segmentIndustryData insertObject:s atIndex:index];
}


a dealloc method takes care of releasing the arrays and dictionary. Anyway, 
even without retain, the table doesn't reload data.



I do not think naming is the issue, it is more of the good habit to have.


 Thanks.




-Original Message-
From: Alexander Spohr [mailto:a...@freeport.de]
Sent: Sunday, December 20, 2009 09:52 AM
To: aronis...@afroamerica.net
Cc: cocoa-dev@lists.apple.com
Subject: Re: NSTableview datasource issues

Did you set a breakpoint on the data source methods?Please reread about memory 
management. Your code is full of wrong retains.Why is segmentDict a global 
variable? You just assign to it but never release it.segmentIndustry is a class 
and should be named with a capital S.segmentIndustryData is always empty. How 
should it populate your table view? atzeAm 20.12.2009 um 02:09 schrieb 
aronis...@afroamerica.net: I know this has been discussed before, but I have 
been going through the issue of reloadData and datasource methods not running. 
I cannot figure out what is going on with my datasource methods. Everything is 
connected. But when on [segmentTableView reloadData], no datasource method is 
run. After the application was running, I debugged the code and checked the 
classes of SelectorController and TableSource. They are all connected in 
runtime.For table view, I only connected it to SelectorController - 
segmentTableView, and its dataSource to SelectorController - segmentTableView. 
All of them are connected properly in runtime.In Log, when I print the 
datasource and delegate of SegmentTableView, it shows SelectorController.  
This is troublesome as I have 4 other tables in the same application that are 
loaded properly through their dedicated datasources. It is only in this table 
that nothing is working. What am I missing? Your help is invaluable.   Her 
is some of the relevant code:   // SelectorController.h #import  
@classsegmentIndustry;   @interface SelectorController : NSObject { 
NSMutableArray *segmentIndustryData; IBOutletNSTableView *segmentTableView; 
IBOutletNSArrayController *segmentDataController;  IBOutletNSButton 
*stockSelectButton; intmodelRS;  }  -(void) insertObject:(segmentIndustry 
*) s inSectorDataAtIndex:(int)index;  -(IBAction) 
initializeSectorSegmentData:(id) sender; @end// SelectorController.m 
   #import SelectorController.h #import segmentIndustry.h #import 
MyDocument.h   NSDictionary *segmentDict;   @implementation 
SelectorController   - (id)init { self = [superinit]; if (self) {  // 
Add your subclass-specific initialization here. // If an error occurs here, 
send a [self release] message and return nil. segmentDict 
=[NSMutableDictionarydictionary]; [segmentDictretain];  } return (self); 
} - (void)awakeFromNib { segmentIndustryData=[[NSMutableArrayalloc] init]; 
[segmentIndustryDataretain]; segmentDataController=[[NSArrayControlleralloc] 
init]; [segmentDataControllerretain];   } //Load into TableView in the 
GUI #pragma mark Table view dataSource methods   - (int) 
numberOfRowsInTableView:(NSTableView *) TableView { return 
[segmentIndustryDatacount];  }   -(id)tableView:(NSTableView *)aTableView 
ObjectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { 
 NSString *identifier =[aTableColumn identifier]; segmentIndustry *stock 
=[segmentIndustryDataobjectAtIndex:rowIndex]; return [stock 
valueForKey:identifier];  }   -(void) tableView:(NSTableView *) 
aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *) 
aTableColumn row:(int) rowIndex { NSString *identifier =[aTableColumn 
identifier]; //What stock? segmentIndustry *stock 
=[segmentIndustryDataobjectAtIndex:rowIndex]; [stock setValue:anObject 
forKey:identifier];  //Set the value for the attribute named identifier }  
  -(IBAction)initializeSectorSegmentData:(id) sender { 
segmentDict=[[MyDocumentgetSectorSegmentData:(id) sender] mutableCopy]; 
[segmentDictretain]; NSWindow *w =[segmentTableViewwindow]; 
[wmakeKeyWindow]; //Fill the table row by row; int i=0; NSMutableArray 
*aXtemp; if ([segmentIndustryDatacount]0) 
[segmentIndustryDataremoveAllObjects]; [[segmentDataControllercontent] 

Re: NSTableview datasource issues

2009-12-20 Thread aronisoft
 Greg,


I understand your proposition. For some reason, the spaces are stripped off by 
the e-mail system, but you got it right.
 Actually, segmentDict contains the copy of a global dictionary created by the 
method [[MyDocument getSectorSegmentData:(id) sender]  mutableCopy]. 
Unfortunately i cannot give here all the code. Also, when I print the 
datasource and delegate for segmentTableView, it is clear that it is not nil: 
the log shows SelectorController, which is what it should be.
My major puzzle is that all other TableView in the application using different 
datasources get loaded. Cleaning all targets does not change anything.
Brief, the major problem is this: the datasource methods do not get called.
Datasource is not nil at run time, no error in the code. The ArrayController is 
not empty, the code looks fine.


I will go back and review for the thousandth time the code from scratch and all 
the bindings, but up to now, I can't figure out what is wrong.


Thank you.


-Original Message-
From: Greg Guerin [mailto:glgue...@amug.org]
Sent: Sunday, December 20, 2009 03:08 PM
To: 'list-cocoa-dev'
Subject: Re: NSTableview datasource issues

 Yes, I set the breakpoint on the data source methods? The  datasource 
 methods are not reached at all.Then you must consider the possibility that 
 your table view has a nil data source, or a data source of a different 
 class.If the methods definitely aren't being called, then simple logic 
 suggests your problem lies somewhere other than that data-source class. 
 Perhaps in the creation or assignment of the data-source. Perhaps in the 
 creation or use of the table view. You'll have to backtrack it to find 
 out.Another possibility is some kind of error or mismatch between your source 
 and your compiled code, where what's loaded and debugged isn't what you have 
 in your source. Doing a Clean build usually fixes such errors. 
 -(id)tableView:(NSTableView *)aTableView 
 ObjectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex 
 {I'm pretty sure that's the wrong method name. Check the capitalization.If 
 your source code is correct, then it was probably mangled by mailing. The 
 list-archives post was also stripped of a lot of necessary whitespace, so 
 capital-mangling would not surprise 
 me.http://lists.apple.com/archives/cocoa-dev/2009/Dec/msg01215.html 
 -(IBAction)initializeSectorSegmentData:(id) sender { 
 segmentDict=[[MyDocument getSectorSegmentData:(id) sender]  mutableCopy]; 
 [segmentDict retain]; NSWindow *w =[segmentTableView window]; [w 
 makeKeyWindow]; //Fill the table row by row; int i=0; NSMutableArray 
 *aXtemp; if ([segmentIndustryData count]0) [segmentIndustryData  
 removeAllObjects]; [[segmentDataController content] removeAllObjects]; for 
 (id key in segmentDict)(Note: I have inserted spaces in the above based on 
 what seems reasonable. I may have guessed wrong.)This code looks odd, 
 especially considering you're also setting segmentDict to an empty dictionary 
 in the -init method. The assignment to segmentDict in -init may be 
 problematic, depending on where else that global variable is used.First, 
 getSectorSegmentData appears to be a class method. That seems unusual to me. 
 It may be justified, but it still seems unusual.Second, it's unclear whether 
 the returned dict assigned to segmentDict actually contains anything or not. 
 If not, then the 'for' loop will get no keys, the loop body will never 
 execute, and self's ivars will contain no objects. If that happens, then the 
 data- source has a count of 0 and contains nothing.A data-source which 
 contains nothing differs from a data-source's methods never being called or a 
 data-source object being nil. The visible effect may be similar, an empty 
 table-view, but the execution path is different. -- 
 GG___Cocoa-dev mailing list 
 (Cocoa-dev@lists.apple.com)Please do not post admin requests or moderator 
 comments to the list.Contact the moderators at 
 cocoa-dev-admins(at)lists.apple.comHelp/Unsubscribe/Update your 
 Subscription:http://lists.apple.com/mailman/options/cocoa-dev/aronisoft%40afroamerica.netThis
  email sent to aronis...@afroamerica.net
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


NSTableview datasource issues

2009-12-19 Thread aronisoft
I know this has been discussed before, but I have been going through the issue 
of reloadData and datasource methods not running. I cannot figure out what is 
going on with my datasource methods.
Everything is connected. But when on [segmentTableView reloadData], no 
datasource method is run.
 After the application was running, I debugged the code and checked the classes 
of SelectorController and TableSource. They are all connected in runtime.For 
table view, I only connected it to SelectorController - segmentTableView, and 
its dataSource to SelectorController - segmentTableView. All of them are 
connected properly in runtime.In Log, when I print the datasource and delegate 
of SegmentTableView, it shows SelectorController.

This is troublesome as I have 4 other tables in the same application that are 
loaded properly through their dedicated datasources.
It is only in this table that nothing is working. What am I missing? Your help 
is invaluable.


Her is some of the relevant code:


// SelectorController.h
#import Cocoa/Cocoa.h
@classsegmentIndustry;


@interface SelectorController : NSObject {
NSMutableArray *segmentIndustryData;
IBOutletNSTableView *segmentTableView;
IBOutletNSArrayController *segmentDataController;

IBOutletNSButton *stockSelectButton;
intmodelRS;

}

-(void) insertObject:(segmentIndustry *) s inSectorDataAtIndex:(int)index;

-(IBAction) initializeSectorSegmentData:(id) sender;
@end



// SelectorController.m



#import SelectorController.h
#import segmentIndustry.h
#import MyDocument.h


NSDictionary *segmentDict;


@implementation SelectorController


- (id)init
{
self = [superinit];
if (self) {

// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
segmentDict =[NSMutableDictionarydictionary];
[segmentDictretain];

}
return (self);
}
- (void)awakeFromNib
{
segmentIndustryData=[[NSMutableArrayalloc] init];
[segmentIndustryDataretain];
segmentDataController=[[NSArrayControlleralloc] init];
[segmentDataControllerretain];


}
//Load into TableView in the GUI
#pragma mark Table view dataSource methods


- (int) numberOfRowsInTableView:(NSTableView *) TableView
{
return [segmentIndustryDatacount];

}


-(id)tableView:(NSTableView *)aTableView
ObjectValueForTableColumn:(NSTableColumn *)aTableColumn
 row:(int)rowIndex
{

NSString *identifier =[aTableColumn identifier];
segmentIndustry *stock =[segmentIndustryDataobjectAtIndex:rowIndex];
return [stock valueForKey:identifier];

}


-(void) tableView:(NSTableView *) aTableView
 setObjectValue:(id)anObject
 forTableColumn:(NSTableColumn *) aTableColumn
 row:(int) rowIndex
{
NSString *identifier =[aTableColumn identifier];
//What stock?
segmentIndustry *stock =[segmentIndustryDataobjectAtIndex:rowIndex];
[stock setValue:anObject forKey:identifier];

//Set the value for the attribute named identifier
}







-(IBAction)initializeSectorSegmentData:(id) sender
{
segmentDict=[[MyDocumentgetSectorSegmentData:(id) sender] mutableCopy];
[segmentDictretain];
NSWindow *w =[segmentTableViewwindow];
[wmakeKeyWindow];
//Fill the table row by row;
int i=0;
NSMutableArray *aXtemp;
if ([segmentIndustryDatacount]0) [segmentIndustryDataremoveAllObjects];
[[segmentDataControllercontent] removeAllObjects];
for (idkeyinsegmentDict)
{
aXtemp = [NSMutableArrayarrayWithArray:[(NSArray 
*)[segmentDictobjectForKey:key] mutableCopy]];
if ([(NSString *) [aXtemp lastObject] intValue]== modelRS) {
[aXtemp insertObject:(NSString*) keyatIndex:(NSUInteger)1];
segmentIndustry *s = [[segmentIndustryalloc] init];
[s setSegName:(NSString *)[aXtemp objectAtIndex:(NSUInteger) 0]];
[s setSegOther:(NSString *)[aXtemp objectAtIndex:(NSUInteger)1]];
[s setSegIndustry:(NSString*)[aXtemp objectAtIndex:(NSUInteger)2]];
[s setSegSector:(NSString *)[aXtemp objectAtIndex:(NSUInteger) 3]];
// Add it to the content array of 'stockDataController'
[segmentDataControlleraddObject:s];
[selfinsertObject: s inSectorDataAtIndex:(int)i];
++i;
}
}

//Re-sort (in case the user has sorted a column
[segmentDataControllerrearrangeObjects];

// Get the sorted array

 NSArray *a = [segmentDataController arrangedObjects];
 for ( i=0;i[a count];++i) {
[segmentTableView editColumn:0 row:i withEvent:nil select:YES];

[segmentTableViewreloadData];

}




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com