UITableView details as a subview - iphone

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 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];

Related

Stop cell from being dragged out of UITableView bounds

I have a UIVIew on which I loaded a UITableView as subview. The tableView is exactly the height of all it's rows(4 of them) heights sumised, about half the height of the main view.
The problem is that when I drag a row to move it I am able to drag beyond the bounds of the table and this cuts my cell's view (I am only able to see the part that is still in the table's bounds).
Is there a property I can change to stop the cell from being dragable out of the table's bounds?
you can do this like below..
[yourtableview setBounces:NO];
let me know it is working or not!!!!
Happy Coding!!!
If the UITableView is exactly the height of the 4 rows . Then you Do Not Need the Scrolling functionality of the UITableView and you can simply stop the scrolling by :-
TableView.scrollEnabled = NO;
Hope this is what you wanted . Please tell otherwise.

How to move tableView up inorder to popUp a view from bottom So that it is not on top of table in iPhone

I have a tableView.It exists from half portion of iPhone screen to bottom.If I click any cell a
popup comes up from bottom. When it appears on the screen table should move up,So that popup does
not overlap on tableView.
Can anyone suggest How to do this.
Thanks in Advance.
Set,
CGPoint _contentOffset = CGPointMake(tableView.contentOffset.x, aNegativeYValue);
tableView.contentOffset = _contentOffset;
If you want it animated, use,
CGPoint _contentOffset = CGPointMake(tableView.contentOffset.x, aNegativeYValue);
[tableView setContentOffset:_contentOffset animated:YES];
You can also use table view's scrollToRowAtIndexPath:atScrollPosition:animated: method.
The simplest way is to embed your tableView (and your other views, since you apparently have more than one view on screen) in a UIScrollView.
Then when you present the popup window on screen, calculate an offset to scroll to by getting your popup window's size,
then slide up the tableView using [scrollView setContentOffset:MyOffset animated:YES].

UITableViewController, getting bounds of visible area

I've got this question. In my app I have many cells. When user clicks on something I'm loading VC and pushing it. To indicate this behaviour I'm displaying a subview which informs that now application is loading. Problem is, when user scrolls down and taps on cell my subview still is on the top of the tableView thus user isn't seeing it.
I need to change frame of my subview so my user can see it. I want this frame to be the center of the current view. How I can do that?
Fore example: My content is 800 pixels worth of height, now I'm displaying at 400 pixels subview with specific information about loading. When my user scrolls down to a cell that is at 2400 pixels, I'm still displaying subview at 400 pixels and thus it is unviewable by user.
I was trying to calculate new frame.origin.y by checking y of a cell that is tapped. Problem is the cell at 2400 pixels could be the first cell user is seeing or the last one, so how I can get the middle of the screen?
Edited with some screens:
When I select first time:
When I select after scrolling down big time:
What it looks like you have done here is added the loading view as a subview to the UIScrollView. You need to add the loading viewController into the parentView after the scrollview.
If this cant be done because your viewController is a subclass of UIScrollview, change it to a regular UIViewController subclass but implement the scrollView protocols and then do as i have said above. Other than that you would have to map the frame of the loading ViewController to the offset on the scrollView-not a good idea.

Prevent subview from scrolling in a UIScrollView

I have a UIScrollView subclass with a certain subview I'd like to prevent from scrolling (while all the other subviews scroll as normal).
The closest example to this I can think of is UITableView's "index strip" on the right side (look in the Contacts app to see an example). I am guessing this is a subview of the table (scrollview) but it does not move as the user scrolls.
I can't seem to make my subview stay put! How can I accomplish this?
The trick is to adjust the frame of the "non-scrollable" subview inside -layoutSubviews.
Add the view that you want not to move as a sibling view of the scroll view on top of the scroll view instead of as a subview.
You can set it's property called userInteractionEnabled to NO

Anchor a UIView

I have a UITableViewController inside of a UINavigationController.
I want to have a UIView appear over the top of the table view but not susceptible to the scrolling of the table view.
I.e. if the table view is scrolled, the UIView should remain in the same position relative to the screen, rather than relative to the table view. It should appear anchored in a certain position.
What is the best way to achieve this?
EDIT: To clarify, the view should float transparently over the top of the table view.
Many thanks!
I also wanted to have a floating UIView over my tableView.
So, within my RootViewController (which is a UITableViewController), this worked for me
- (void)viewDidLoad {
/* mylabel is a UILabel set in this class */
[self.mylabel setUserInteractionEnabled:NO];
/* navigationController comes from higher up in the navigation chain */
[self.navigationController.view addSubview:self.mylabel];
}
Similar to what Peter said, create a UIView that will contain both the TableView and the subclassed UIView. Such as:
UIView *view = [[UIView alloc] initWithFrame:frame]; // Define frame as you like
[view addSubview:myTableView]; // This is the reference to your tableView
[view addSubview:myAnchoredView]; // This is the reference to your UIView "floating" subclass
You will also need to turn off user interaction for your floating view. I don't know if this will specifically pass the touches to the underlying UIView's or not though:
[myAnchoredView setUserInteractionEnabled:NO];
If this is blocking touches to your tableView, you may need to pass the reference to your tableView to the anchored view at initialization, then pass the touch events along. You can do this by overriding the touch response methods in UIResponder. (If there is a better way, someone please speak up.)
Do you mean the anchored view should appear transparent over the UITableView, or just above, i.e. anchored view uses top 20% of the available space, table view uses the rest?
In any case, create a UIView containing the anchored view and the table view. If you want the anchored view transparent over the table view, it's a bit tricky, because to scroll the table view, touches have to pass through the anchored view.
Add the surrounding view's view controller to the navigation controller instead of just the tableview.
I investigated how UIScrollView keeps its scrollIndicator above the UIScrollView's content and yet unmoving by examining a UIScrollView in the debugger.
The scrollIndicators are UIImageViews. And you can see they are direct descendants of the UIScrollView itself. You can also see that any scrolled content is also a direct descendent. So how is it that the scroll indicators don't move?
I tried updating the position of my static content constantly in - (void)scrollViewDidScroll:(UIScrollView *)scrollView this, surprisingly, works. I'm not sure if it is how UIScrollView itself does it, but without some private magic, it must be something like this.