• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Beginner question - Cocoa outlet using a method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Beginner question - Cocoa outlet using a method


  • Subject: Beginner question - Cocoa outlet using a method
  • From: Denis Stanton <email@hidden>
  • Date: Sun, 26 Jan 2003 14:29:56 +1300

I'm just starting with Cocoa. I've worked through some tutorial
examples and now I'm trying to branch out. I have written a very
simple extension to an example, but it doesn't work the way I expect.
Can someone tell me what I've missed?

The program displays a Table View. I'm trying to add a simple text
field to display the number of rows. I have a numberOfRowsInTableView
method so I thought it would be simple to connect this to a text field
set up in IB as follows:

-------- MyDataSource.h -----------
#import <Cocoa/Cocoa.h>
@interface MyDataSource : NSObject
{
IBOutlet NSTextField *numberOfRowsInTableView;
NSMutableArray *myArray; // initialization code not shown
}
@end

-------- MyDataSource.m --------
#import "MyDataSource.h"
@implementation MyDataSource
- (int)numberOfRowsInTableView:(NSTableView *)tableView {
return [myArray count];
}
@end


This does not work. The text field connected to the
numberOfRowsInTableView outlet in Interface builder never receives the
count of the array rows.

I have found that I can get around this by declaring an instance
variable for the IBOutlet and then explicitly assigning it a value
inside the numberOfRowsInTableView method.


-------- MyDataSource.h -----------
#import <Cocoa/Cocoa.h>
@interface MyDataSource : NSObject
{
IBOutlet NSTextField *myNumberOfRows;
NSMutableArray *myArray; // initialization code not shown
}
@end

-------- MyDataSource.m --------
#import "MyDataSource.h"
@implementation MyDataSource

- (int)numberOfRowsInTableView:(NSTableView *)tableView {
[myNumberOfRows setIntValue: [myArray count]];
return [myArray count];
}


This works, but it looks very clumsy to me. I would have thought that
the method that returns the rows could be connected directly to the
outlet rather than have to communicate through an extra variable.

Have I missed something basic?

Thank you for your time in reading so far

Denis
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Beginner question - Cocoa outlet using a method
      • From: Jeff Disher <email@hidden>
References: 
 >Re: Converting CGShieldingWindowID() to NSWindow? (From: Pierre-Olivier Latour <email@hidden>)

  • Prev by Date: Re: cascading sheets and HIG
  • Next by Date: Re: adding subViews, not showing up
  • Previous by thread: Re: Converting CGShieldingWindowID() to NSWindow?
  • Next by thread: Re: Beginner question - Cocoa outlet using a method
  • Index(es):
    • Date
    • Thread