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

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
}

Related

Show the other view controller in one common view controller like slide menu

I have one view controller called homeviewcontroller. In that i placed one right bar button item And i have added one uiview under that bar button item. when i click my bar button item it will show the uiview.In that uiview i have two button option.
A view controller
B view controller
I also create a two view controller with story board identifier. Avc , Bvc. So what i need is. When i click the buttons in my UIVIEW that respective A Viewcontroller or B viewcontroller should show in my `home Viewcontroller'. I have that two button action like this:
- (IBAction)ButtonONEClicked:(id)sender {
}
- (IBAction)ButtonTwoClicked:(id)sender {
}
How can i code that to show that two A Viewconroller and B viewcontroller in my homeViewcontroller.Here is my image of that uiview placed in my HomeViewcontroller
Please help me how to do that.Thanks
have you used container view controller -
if not so here -
1.https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html
Best Tutorial - a.https://spin.atomicobject.com/2015/07/21/ios-container-views/
b.http://www.thinkandbuild.it/working-with-custom-container-view-controllers/
Swift version - https://github.com/codepath/ios_guides/wiki/Container-View-Controllers-Quickstart

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.

Passing a Custom Cells image views image to a new view controller

I have a view controller which has a UITableView with some custom cells.
Within the custom cells I have a main UIImageView. I add a tap gesture recogniser to the image view, so that when the image is tapped the handleImageTap method is called.
Question
What I am trying to do is pass the image from the selected UIImageView (from the specific cell) into a new View Controller.
When the handleImageTap is called I run the following:
UIImageView *imageView = (UIImageView *)gestureRecognizer.view;
// send the image instead of self when firing the segue
[self performSegueWithIdentifier:#"remindMeTurnInfo" sender:imageView];
I then have the following in the prepareForSegue method:
if ([segue.identifier isEqualToString:#"remindMeTurnInfo"]) {
UIImageView *imgView = (UIImageView *)sender;
MESPlayedTurnReminderViewController *VC = segue.destinationViewController;
VC.mainImageView.image = imgView.image;
}
The above does not work the image is not passed across. How can I get the image from the selected cells image view to the new controller?
Also
Sometimes when the image view of the cell is selected the didSelectRowAtIndexPath method is called. This is not correct and should not be called when the image view is tapped. This doesn't appear to be all the time, is there anyway to ensure this is not called?
I also need a reference to the cell that the imageview is within for the prepareForSegue method. How do I get the reference for the cell that the imageview is within, when the cell is (should not be) actually selected here.
Your question has 2 problems.
First, you should not use table view cells to store data. Table view cells are view objects. They display data. When the user triggers an action on a cell, you should figure out the indexPath of the cell, use that info to look up the data in your model (the image for the selected row or section/row, in your case) and use that.
Second, you should never try to manipulate another view controller's views. Treat the other VC's views as private. This is a biggie. Reaching into another VC and touching its views violates the encapsulation of the two VCs and means that the VC doing the touching becomes dependent on the appearance of the "touched" VC. Bad. Then you can't change the appearance of the touched VC without breaking other code. It also doesn't work right after creating the new VC, because it's views don't exist yet.
Instead, you should add an "imageToUse" property to the other view controller, and set THAT in the prepareForSegue method. Then the second view controller can take the image and install it in it's image view in it's viewWillAppear method.
I changed the approach.
Putting a UIImage on the destination Controller instead. Then in the viewDidLoad of this controller I pass the image into the UIImageView. I imagine this is because the image view is not created yet.

popover content view doesn't display while viewcontroller has a child VC present

I have a container view controller that consists of a navigation view at top, and a content view for the remainder of the screen. The navigation menu consists of several buttons, some of which present a popover with UITableView for secondary navigation. This all worked until I assigned a child view controller and set it's view as subview of the content view. Now, the popover appears, but has nothing inside it (no tableview, just black).
Why is this?
Here's the code I added for the child vc in container view:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
ContentWebViewController *initialVC = [[ContentWebViewController alloc] init];
[self addChildViewController:initialVC];
initialVC.view.frame = self.view.bounds;
[self.containerView addSubview:initialVC.view];
self.currentController = initial;
}
See the screenshot below. I added a vc with a simple webview showing google (just as a placeholder for now). The popover was working fine before I assigned the child VC.
Maybe it will help other in other cases -
If you are using size classes (probably you are since you are developing this to iPad) -
Design your popover view controller in Any-Any size and it should be OK - after that you can return to your wanted size.
(You can also uninstall the size classes of any object in that view controller instead of redesign the VC)
I somehow (don't ask me how) changed the class that my table view controller was inheriting from. It should have been (obviously) UITableViewController, but was UITableViewController, so initWithStyle was not being called....

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

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

Resources