Static Table View cell seque to ViewController clicking in Cell - ios

When I create a table view with static cells, and connect cell with other ViewController in storyboard and run this, It is seque when clicked in disclosure indicator, but when click in cell it`s nothink. How can I seque it with click on the cell?

Control drag your cell to the other view controller and click the first modal. Not the one under accessory action.

Related

is it possilbe to uiview, detect from pop navigation controller?

I have a collectionview called "A" inside another collectionView cell,
in collectionView "A"'s cell, there is uiView.
In this uiview I play some animation.
When I click collectionView "A"'s cell, It pushes navigation controller, and I stop the animation.
I want to play animation again when I pop navigation controller.
Is it possibe to uiview, detect when view is appear again?
I know uiviewcontroller has viewdidload or viewwillapper to detect, but i need uiview to know.
You'll have to keep a weak reference of that cell and you can access the specific view when you pop the view controller.
Save the index you clicked and get that specific cell using this line and play the animation collectionView.cellForItem(at: IndexPath)

Tab Bar disappears on segue

What I want to achieve:
I have a "Login" ViewController which segues to a Tab Bar Controller.
My Tab Bar Controller goes to a Navigation Controller and then "Home" ViewController with a Table View. This view is my "Home/Welcome" page. I want there to be a Tab Bar at the bottom as well as a static table which I can edit with Prototype Cells. Each cell goes to a different ViewController.
Then, I want to be able to tap each Cell (I have "Info" setup for now) and it segue to the corresponding ViewController. For now, the "Info" cell should go to the second Navigation Controller and then "Information" ViewController.
From there, I want another static table which I can edit with Prototype Cells. Each cell will go to a seperate stack of ViewControllers.
My problem:
When I segue from the "Info" cell in the "Home" ViewController, the Information tab bar "pushes" up, and the Tab Bar disappears. I've experimented with other segue forms but none of them maintain the Tab Bar.
I want it so you can use either the Tab Bar to navigate to the Info ViewController or the cell on the Home/Welcome ViewController to navigate to the Info page.
I have no code at all at this point, I am just using these segues.
Does anyone have any idea how I can achieve what I want to achieve, and if so, provide as much sample code as I'm extremely new to Swift.
Any help is appreciated! Thanks :)
Don't add segue to open the "Information" ViewController which is part of UITabBarController.
You must have used didSelectRowAt for cell selection in tableview. Just add one line in it as it is :
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true) {
self.tabBarController?.selectedIndex = 1
}
This will change the tab and open the "Information" ViewController.
If you want to load the "Information" ViewController with data relevant to cell selection you can go with Protocols or NotificationCentre which can pass data to "Information" ViewController from Homeviewcontroller on cell selection.

How to change button name when cell selected in UITableView in swift?

I have two UIButton and when you click on each you will go to table view controller and there you can select something.
My question is how to change the button title on selection of any cell.
I want to replace button title with selected cell's name.
There are two ways to pass data back to the previous viewController.
1) Using Delegates, check this
2) Using Notifications, check this
Bind button in your cell as #IBOutlet
When cell selected delegate method tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. Here you can get your cell with [tableView cellForRowAtIndexPath:indexPath]
Change your button's title [cell.yourButton setTitle...]
If you were to make your navigation controller into you root view controller and put the view controller you wish to access the buttons from as its top view controller then you could do the following when a cell is tapped:
if let topVC = navigationController?.topViewController as? MyButtonViewController {
topVC.button1Name.setTitle("New Title", forState: .Normal)
}
Then you can hide the navigation bar on the top view controller with the following:
override func viewWillAppear(animated: Bool) {
navigationController?.setNavigationBarHidden(true, animated: animated)
}
override func viewWillDisappear(animated: Bool) {
navigationController?.setNavigationBarHidden(false, animated: animated)
}
Instead of using two navigation controllers you can use a single NavC and then make your view controller with the two buttons as the root view controller. Then when the buttons are pressed you load the appropriate table view controller. Also if your table view controller has the same data source then you can use a single table view controller itself.
Then depending on which button is pressed you push the appropriate table view controller but in the prepareForSegue keep track of which button was pressed so that you can change its title when a cell is selected in the table view controller.
To pass the selected cell details from the table view controller you can make use of a delegate which your view controller can implement and the table view controller will call and pass the selected cell details.
So in short do this.
Make your navC as the initial view controller.
Make your view controller with the two buttons as the root view controller of the navC
In the IBAction of the two buttons store which button was pressed so that you will know which buttons's title has to be changed.
When you load table view controller set the view controller as a custom delegate.
In the language list table view controller's didSelectRowWithIndexPath use the delegate to pass the selected cell info and pop the view controller.
In the delegate method of the view controller change the button title that you have stored in step 3 to the selected cell's text.
I have another solution which I have uploaded here. It does not contain any custom view controllers except the ViewController that has the two buttons. It makes use of segues and unwind segues.
http://www.filedropper.com/twobuttonnavc

How can I create a segue between a custom UITableViewCell button and a second view

I created a custom UITableViewCell in a separate nib, and inside it I have a button. I want the tableViewCell to segue to one view controller when the cell is tapped, but a different one when the button is tapped. The cell tap segue works fine, but I can't figure out how to setup a segue between the button in the cell and the next view. I have added a target to the button with
cell.imagePreview.addTarget(self, action: "segueToImageView:", forControlEvents: .TouchUpInside)
Then in that method
#IBAction func segueToImageView(sender: UIButton) {
performSegueWithIdentifier("ImageViewSegue", sender: self)
}
But obviously I end up with a "has no segue with identifier 'ImageViewSegue'" error. I tried connecting the button to the new view in my main.storyboard, but it won't let me drag between the nib and the storyboard. I also tried creating a segue in main.storyboard between the two views and calling it "ImageViewSegue" but I get the same error.
Is there a way to create a segue with identifier through code? If not, how should I go about segueing to the new view via the button?
Instead of a segue, just do this the old-fashioned way (from before there were storyboards and segues): set the button's action–target pair (in code, when you load) so that when the button is tapped, your action handler is called. In the action handler, do whatever the segue would do, i.e. instantiate the view controller from the storyboard and push or present it.

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