Custom Raised Button action not navigates to Tabbarİtem - ios

İ have created a custom raised button in tabbarviewcontroller. Already added a custom action on button for selectedindex = 2.
Problem I am facing first time button clicked is working fine shows second tabbar item and perform action but if I re-clicked button again it won’t show tabbar item view. To check button status I use print command and its printing that button clicked.
Tabbarviewcontroller —> tabbarİtem 2 —> webview
As it stays on webview controller but On re-click of button İ need it come backs(navigates) to tabbarİtem 2.(refresh view as navigatecontroller performs back button). Behind the custom button - tabbarbar item for item2 (link able) is working but not on button.
#objc func buttonAction(sender: UIButton!) {
print("clicked button")
selectedIndex = 2 //// button click to open tabbar item 2
}

Related

How to segue from tab bar view controller to another view which is a child of a navigation controller

I laid out my home screen (Summary screen) as shown on the screenshot below:
I added the "+" button on the UITabBarController subclass. This button will segue to a view controller and show it modally. To give you a bit of context on how I've structured my storyboards, please refer to the screenshot below:
This modal view controller has a form that the user needs to fill in, and once they're done, there's a 'Done' button which will 1) dismiss the modal, 2) take them back to the root view which is either the 'Summary' tab or the 'Details' tab then 3) take them to a list view showing the most recent data they've entered on a list (destination view – highlighted in red).
Now, doing the segue when the user taps the "+" button is simple enough. With the following code:"
menuButton.addTarget(self, action: #selector(menuButtonAction(sender:)), for: .touchUpInside)
then
func addNewExpense(action: UIAlertAction){
self.performSegue(withIdentifier: "segue_formModal", sender: self)
}
On the modal I've setup a protocol which will then send the form data back to the tab view controller.
extension XtabBarViewController: NewInfoDelegate{
func newInfoSubmitted(formData: FormData) {
performSegue(withIdentifier: "segue_ListingPage", sender: self)
}
}
But it seems that the perform segue is not working. It says the segue does not exist. "segue_ListingPage" is that segue that connects the Summary view and the destination view.
How can I segue from the tab bar view controller to the destination view? Any help is appreciated.
Thanks in advance!
You can just make the navigation view controller the entry point.
I figured it out on my own. For the benefit of those who run into the same issue here's my solution.
I simply added the code from the tab bar view controller the code:
let childVC = children[0].children[0]
childVC.performSegue(withIdentifier: "segue_TXListPage", sender: self)
So what I did here is call the performSegue from the view controller that segues to the destination controller.

Mark mobile app menu button when there are new items

There are few ViewControllers in my app and all of them have menu button. When this button is pressed - menu ViewController is opened.
I want to mark menu button with red dot showing that some new content is available and user need to press menu button to see which one of menu item is marked with this dot.
As all my buttons are independent of each other - I thought that I need to solve it this way
Add red dot image on each menu button
Make this dot hidden by default
When each ViewController is opened - i should check - are there any new items available and switch isHidden property of this red dot image to false.
But maybe there is some more elegant way?
use NotificationCenter to notify the ui when new content available
in the menu viewcontroller class:
//put this in viewDidLoad
NotificationCenter.default.addObserver(self.selector : #selector(menuviewcontroller.refresh(_:)),name:NSNotification.Name(rawValue:"showRedBtn"),object : nill)
//create function refresh
func refresh(_ notification : Notification)
{
//make the red dot visible
}
create class that listen if any content added and call the delegate in case of add by this line of code
NotificationCenter.default.post(name : Notification.Name("showRedBtn"),object : nil , userInfo : nil)
hope it's will help you

What is triggered when "Done" is pressed after changing from "Edit" in UINavigationItem bar for UITableViewController?

Short: In Swift/iOS, when does the "Done" (which was previously "Edit") nav bar button trigger when getting out of the UITableViewController "Edit" mode? When the user presses "Done" I'd like to enable a "+" button in my UINavigationItem bar so the user can once-again add rows by migrating to another view controller.
Longer: When a UITableViewController is showing below a UINavigationItem nav bar, there is an "Edit" button which turns into "Done" after it's clicked to enable deletes & move/drags. Works great when this button is enabled via uncommenting code in viewDidLoad() generated as part of the UITableViewController class:
self.navigationItem.leftBarButtonItem = self.editButtonItem
I've got my move/drags & deletes working fine, but I want to appropriately disable my "+" button (addBarButton, used for navigating to another view controller to add a new row) while the user is in the Edit mode. I'd then like to re-enable addBarButton after the user has clicked "Done" (which turns back into "Edit").
It looks like disabling addBarButton during the func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) is correct. If I read Apple's docs right, this is triggered when user presses Edit in the nav bar. What I don't know is what is triggered when the user presses "Done" (the button formerly labeled "Edit"). If I enable my addBarButton "+" button after the func tableView with moveRowAt, this enables addBarButton before the user has pressed "Done".
The Apple doc I'm referencing is at:
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html#//apple_ref/doc/uid/TP40007451-CH11-SW1
Apologies if I'm missing something obvious. Thx
The answer is right in the description for the UIViewController editButtonItem documentation:
If one of the custom views of the navigationItem property is set to the returned object, the associated navigation bar displays an Edit button if isEditing is false and a Done button if isEditing is true. The default button action invokes the setEditing(_:animated:) method.
The last sentence is the key. You should override the setEditing(_:animated:) method in your table view controller subclass. Be sure you call the super implementation and then perform whatever custom action you want based on whether the controller is entering or exiting editing mode.
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
if (editing) {
// User tapped the Edit button, do what you need
} else {
// User tapped the Done button, do what you need
}
}

IBAction on button won't be called in custom keyboard

I am making a custom keyboard that has a search bar. In order for a user to be able to interact with it, they must be able to:
1- Input text with individual letter buttons.
2- Tap the search button.
As for number 1, I have working IBActions that are called at every button press. For example, here's the action for the letter "m":
#IBAction func mPressed(button: UIButton) {
searchBar.text! += "m"
}
However, the search button IBAction will not call:
#IBAction func searchPressed(button: UIButton) {
print("searchPressed")
}
When I connect the search button in storyboard to the "mPressed" action, that action is called. But when I reconnect it back to the "searchPressed" function above, it doesn't work again.
I have also made sure that I correctly connected the button to the action.
The search action is connected to the search button
The 'm' action is connected to the 'm' button
Thanks!
In your screenshot search button connected to method searchButtonPressed, but in code you have method searchPressed.
Delete connection to searchButtonPressed and reconnect to searchPressed and it will work.

I can't figure out how to set the correct button to be unhidden using swift

I'm trying to create a quiz app for a project, I'm having a problem when I try to set another button to be revealed when you select the correct answer. ex.
1+2=?
2
3
5
9
When they select 3, I want the continue button to appear to go to the next page.
#IBAction func Seaturtle(sender: UIButton) {
if sender.tag == 2 {
7.hidden = false
}
}
Go into your Storyboard and find the Continue button you wish to hide/unhide. Use Xcode's split screen view to have both your Storyboard and the associated code file open. Select the button, then Ctrl+Drag from the button into the code, creating an IBOutlet instead of an IBAction. Say you give it the name continueButton. Then, when you want to hide/unhide just call
continueButton.hidden = true
or
continueButton.hidden = false

Resources