Adding Common instance of UIView at zero index of UITableView does not show - ios

The structure of my classes is as fellow
I have a main view controller, let say MainVC;
Four different view controllers, say vc1, vc2,vc3 and vc4; Each vc has its own UITableView;
MainVC displays these VCs as subView;
A sub class of UIView, say headerVC, which returns me a header view which need to show as banner over each table in VCs; This view contains the buttons which switches the Vcs on MainVC;
Now when I run MainVC, it loads the view of VC1 (which has a tableView) and then VC1 adds the headerView at first row of its tableView; When I press any button over headerView, the MainVC toggles the VCs as per selection; Eech VC adds the headerView at first row of its tableView;
Its all works well, but when I navigate away to another tabbar item and comeback, the headerView disappears from selected VC's table; Rest of the rows displays as it is, but header view goes aways; When I scroll the tableView up/down the headerView (in first row) appears again; I'm not getting the reason why it behaving like this;
I tried to put headerView in both tableView's header and section's header but it didn't appear at all; By this approach atleast header view is displaying and working well, but now when I change the tab and come back, only the first row (which contais the header view) disappear;
any clue??

Remove this headerview from row of TableView and add as a static view to the VC, if you want it to move it with the tableView, you can do it via this code
float scrollStartPositionY;
-(void) scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y>=scrollStartPositionY)
header.hidden=YES;
else
header.hidden=FALSE;
header.frame =CGRectMake(header.frame.origin.x,TableView.frame.origin.y TableView.contentOffset.y- header.frame.size.height, header.frame.size.width,header.frame.size.height) ;
}
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
scrollStartPositionY=scrollView.contentOffset.y+5;
}

Related

How to stop TableViewController hitting status bar?

I have a new TableViewController that I dragged from the object library. It is now populated with data. When I run the app, the tableview is going all the way into the status bar. I don't think that is normal.
But I also don't see a way to resize the a tableview on the TableViewController scene. Any one have some suggestions how I should go about fixing this issue?
You can embed your TableViewController in a Navigation controller:
1. Select the TableViewController in the storyboard
2. Xcode top bar: Editor -> Embed in -> Navigation controller
If you don't want to embed your TableViewController in a nav. control, you can add padding to the table view in your viewDidLoad in your TableViewController class:
// ... in TableViewController.swift
override func viewDidLoad() {
super.viewDidLoad()
// add top padding to table view
let myTopPadding: CGFloat = 50
self.tableView.contentInset = UIEdgeInsetsMake(myTopPadding, 0, 0, 0);
// ...
}
Note that with this solution, however, you data will still "hit" the status bar when scrolling, although not when entering your table view. This is apparently and issue that is hard to avoid (without navigation controller) when subclassing the UITableViewController:
iOS 7: UITableView shows under status bar
If you want padding also when scrolling then, based on the thread above, you're better off creating your own table via view controller -> insert table view -> ..., rather than using the finished UITableViewController "package".

I want to pass touch event for a transparent custom cell to its parent view (which is a pageview controller)?

I'm trying for this solution from many days, I have a scenario where I want to pass touch even (Swiping for page view controller) of my first custom cell to the parent view which is a page view controller.
Here my first cell in the table view is a transparent cell. It is not visible instead of we can see the background view which is a super class of table view controller and it is a page view controller. So here I want to pass the touch event which should be swiping for page view controller. And all the remaining cells are not transparent. Here I'm sending the image so that you can understand. easily. So help me out in passing the swipe/touch to my page view controller Basic Look with transparent cell on top So in that transparent cell area we can see the super view of table view controller which is a page view controller.
As you can see left side is the basic look, and in that you can see the page view controller, and then the right side image is when we scroll the cells it will look like this.
So now you can understand clearly the height of table view and my requirement too.
So how to pass touch/ swipe event to the page view controller when we select transparent cell(indexpath.row ==0 first cell)
I tried the solution that given but no use..
You can add one more view on top of it (pageview -> cellview -> new view on top with opacity = 0). Next add swipe gesture to new view and finally make a newView.delegate = pageviewController to capture swipe event.
#protocol NewViewControllerDelegate<NSObject>
-(void)gestureDidFire;
#end
#interface NewViewController : UIViewController
// you gesture outlet look like IBAction *swipeGestureReconizer;
#property (nonatomic, assign)id <NewViewControllerDelegate>delegate;
#end
//newViewContrlloer.m
- IBAction swipeGestureReconizer
{
if(self.delegate && [self.delegate responseToSelector:#seletor(gestureDidFire)])
{
[self.delegate gestureDidFire];
}
}
//in your page view interface
#interface yourPageView()<NewViewControllerDelegate>
{
//need instance of newView
newViewController.delegate = self;
}
-(void)gestureDidFire
{
//implement what you want
}

Add view behind tableview in UITableViewController

I'm trying to add this custom control below my tableview in a TableViewController:
https://github.com/zogieosagie/RMEIdeasPullToSortControl
In the example the creator gives, the control is implemented using a ViewController and an added tableview, but I want to use it in a TableViewController. I have created and initialized it as shown in the example but I cannot get it to show up behind the table. Any ideas?
Here is a screenshot of the control above my tableview: https://www.dropbox.com/s/ojfpacxelcy9cqm/Photo%20May%2028%2C%208%2057%2035%20PM.png
Here is my code in the viewDidLoad method:
[self.tableView setBackgroundColor:[UIColor clearColor]];
self.rmeideasPullDownControl = [[RMEIdeasPullDownControl alloc] initWithDataSource:self delegate:self clientScrollView:self.tableView];
self.sortTitlesArray = [[NSArray alloc] initWithObjects:#"Listed from A - Z", #"Listed from Z - A", #"Brand value: HIGHEST - LOWEST", #"Brand value: LOWEST - HIGHEST", #"Founded: OLDEST - NEWEST", #"Founded: NEWEST - OLDEST", nil];
CGRect originalFrame = self.rmeideasPullDownControl.frame;
self.rmeideasPullDownControl.frame = CGRectMake(0.0, 45.0, originalFrame.size.width, originalFrame.size.height);
//It is recommended that the control is placed behind the client scrollView. Remember to make its background transparent.
//[self.view insertSubview:self.rmeideasPullDownControl belowSubview:self.tableView];
[self.tableView addSubview:self.rmeideasPullDownControl];
[self.tableView sendSubviewToBack:self.rmeideasPullDownControl];
Table view controllers do not lend themselves to managing anything other than a table view. In a table view controller the content view of the view controller is the table view.
You should not try to add other views as subviews of a table view.
Those 2 things combined mean that you can't do what you are trying to do.
Instead, you should create a regular UIViewController. In your storyboard, add a container view to the view controller's content view. Create a UITableViewController as a separate scene, and then control-drag from the container view onto the table view controller. That will set up an embed segue, so your table view controller becomes a child view of the regular view controller. Now you can do whatever you want to the main view controller's content view, including adding other views behind the table view.
Do you mean that you are using a Table View Controller on the storyboard? Or do you mean that your backing code is a subclass of UITableViewController?
I haven't used this project before but I'm guessing you are using a Table View Controller on the storyboard, in which case there is no backing view for the RMEIdeasPulldownControl to attach to (the top-level view is a UITableViewController). If you look in the example it needs to be attached to a scrollview (like a table view) but it needs to be inserted into a view (like a UIView)
If you meant the second one then I'm not sure, UITableViewControllers are subclassed from UIViewControllers and are really very similar, so I can't imagine any trouble arising from that.
It isn't possible directly, but you can create UIViewControllerClass with relevant storyboard UIViewController
add a MyUIView in hierarchy then UITableView next to MyUIView
attach datasource and delegates for UITableView and use MyUIView as per your requirement.

tableView initwithframe and storyboard

I'm trying to add a tableview as subview to my tableViewController, but I want to setup the cells in storyboard. It will be a static tableview.
This is the code for calling the tableview on button click.
- (IBAction)botaoAdicionar:(id)sender {
AtividadesPraticadasTableView *tableview = [[AtividadesPraticadasTableView alloc] initWithFrame:CGRectMake(0, 170, 320, 320) style:UITableViewStylePlain];
[self.view addSubview:tableview];
}
In the tableview class I have this:
#implementation AtividadesPraticadasTableView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
Now, I have a viewcontrollerin storyboard with a tableview, which the class of the tableviewI changed to this file AtividadesPraticadasTableView. It has three static custom cells in storyboard, therefore it opens a blank default tableview.
What am I missing?
Static table views are entirely contained within the storyboard, and require information from the storyboard to display their content.
You've defined a static table view controller in the storyboard, populated it and set the tableView's custom class to your custom class, but when you want to add the table view you are just instantiating a table view of that class. That isn't going to get any of the information you've added to the storyboard.
In addition, the static cells information is read and understood by the UITableViewController, not the UITableView, so you are at the wrong level there too.
You need to do the following:
Get a reference to the storyboard, either from your original view controller's storyboard property (if it is on the same storyboard as your static table) or using storyboardWithName:bundle:.
instantiate the table view controller from that storyboard, using instantiateViewControllerWithIdentifier:. This will create a table view controller object containing all your static cells
Add this as a child view controller to your original view controller, using addChildViewController:
Add the table view controller's tableView as a subview
It may be simpler to add a container view in the storyboard to hold this view, and reveal it when the button is pressed, as Mike Slutsky suggested - this will do all of the instantiating and adding and child view controller-ing work for you, but the principle is still the same.
Also, adding a table view as a subview to a table view controller sounds very dodgy - a table view controller already has a table view as its view, and you can't really add subviews to that.
The thing your missing is the association between the programatically instantiated tableview and the UITableView that you put in your storyboard. You cannot just draw UITableViews in your storyboard and start instantiating new UITableViews in the controller's code and expect xcode to know which UITableView you wanted to use from the storyboard. Use an IBOutlet to connect a global variable for the controller to the UITableView in the storyboard, then the controller will know what you're trying to refer to. If you want that UITableView to appear on a button click, simply set the UITableView to hidden by default in the storyboard and then unhide it when the button is pressed.
The thing You are missing called manual. Check this protocol for TableView dataSource https://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDataSource
P.S. Here good tutorial for storyboards http://maniacdev.com/ios-5-sdk-tutorial-and-guide/xcode-4-storyboard

View added to superview disappearing when navigating tableview

I have a tableView that navigates to a detail view when the user selects one of the tableView cells. This main TableView is created in a UITableViewController class. (MasterViewController)
I used StoryBoard to create the master-detail tableviews.
Within MasterViewController, I lay a tableView over top of the main tableView when the user selects the To button. This second tableView allows the user to select multiple values from this list.
In order to prevent this second tableView from scrolling on the screen when the first (main) tableView scrolls, I have added this second tableView to the superView of the MasterViewController view. ([self.view.superview addSubview:_toView];)
So, in MasterViewController, I add a TableViewController (_toController). I instantiate a UIView (_toView), add a background image to it (_toViewBG) and then add a TableView to it (_toTableView). I then add _toView (which contains this second tableView) to the superview of the MasterViewController view.
_toController = [[ToTableViewController alloc] init];
_toView = [[UIView alloc] initWithFrame:CGRectMake(10,10,263,247)];
_toViewBG = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,257,232)];
_toViewBG.image = [UIImage imageNamed:#"toViewBackground.png"];
[_toView addSubview:_toViewBG];
_toTableView = [[UITableView alloc] initWithFrame:CGRectMake(20,30,220,180) style:UITableViewStylePlain];
[_toTableView setDelegate:_toController];
[_toTableView setDataSource:_toController];
[_toView addSubview:_toTableView];
[self.view.superview addSubview:_toView];
[_toTableView reloadData];
This approach keeps the second tableView from scrolling when I scroll the main tableView. The second tableView stays on top and in place as the main tableView scrolls.
If I select a cell in the main TableView, I navigate to a detailed view. When I return to the main TableView, I am unable to get the second TableView (_toView) to be displayed.
I am not sure how to tell the _toView to come to the front. I realize it is added to the superview of the MasterViewController view. From some experimentation, this superview appears to be a CALayer.
Can anyone suggest how I would get this _toView to display in front of the MasterViewController view?
Thanks in advance for any assistance.
Solved
I ended up just adding the second tableview as a subview of the MasterViewController view.
[self.view addSubview:_toView];
I then disabled scrolling on the main tableview while my second tableview is visible.
Self.tableView.scrollEnabled = No;
Seems to be working fine.
Tim
It may be possible to make this work by calling [self.view.superview bringSubviewToFront:_toView], but my advice would be to make MasterViewController a subclass of UIViewController rather than UITableViewController, and then add both of your UITableView objects as subviews of the root view, (rather than referring to superview).

Resources