views:

40

answers:

1

Hi all,

I have a UITableView in iPhone with enough cell to make it scrollable. I would like to have a subview display whenever I click on a cell, rather than using the navigation controller behaviour.

The problem is that I cannot calculate the CGRect exactly to have the subview always centered in page, because the CGRect is calculated from top of table, and if I scroll table and click cell, the subview will be added out of screen.

The solution could be easy, but I don't know if it's possible: identify the portion of the current viewable area of the UITableView and obtain in some way the frame and therefore origin and size, then build a subview based on such coordinates. Do you think it's possible without writing not too much code ?

thanks Leonardo

A: 

A simple solution is to not add your sub view as a subview of the UITableView but of its parent (or the main application window). So instead of doing something like:

[myTableView addSubview:mySubView];

do:

[[myTableView superview] addSubview:mySubView];
pheelicks
uhm, seems that UITableView doesn't respond to parent, so the application crash.
Leonardo
apparently seems that I have solved, I am using this, instead of using 'parent':[myTableView.superview addSubview:mySubView]
Leonardo
Sorry that was a typo - me being stupid. I meant superview, as you correctly said
pheelicks
You pointed me to the right direction. If you can edit the answer I can mark it is as correct.
Leonardo
I have updated the answer. myTableView.superview is the same as [myTableView superview] in Obj-C. I think it's cleaner to use the bracket notation as it emphasizes the fact that you are sending a message.
pheelicks