You can call [theCell controlView]
to get a reference to the control that owns a particular cell. If the NSTextFieldCell
object is part of a simple control, such as an NSTextField
, the following should be sufficient:
NSRect cellFrame = [[theCell controlView] frame];
NSPoint origin = cellFrame.origin;
//..
If, however, the NSTextFieldCell
is part of a more complex control, such as an NSTableView
, where a single cell is used in multiple places, you will need more information in order to determine the proper rectangle. NSCell
offers the method representedObject
, which can help you to determine which object in the NSTableView
is represented by the cell at that particular moment. Without knowing more about your specific case, I don't know how much more detail to provide in that regard.
Here is one possible solution, assuming you are able to discern the row and column information from the object stored in representedObject
:
NSTableView * tableView = [theCell controlView];
id cellObject = [theCell representedObject];
NSInteger row = //... determine from representedObject
NSInteger col = //... determine from representedObject
NSRect cellFrame = [tableView frameOfCellAtColumn:col row:row];