I have a View Controller where I select some data into an array and then optionally on clicking of a button I show that data in a TableView added as a subview to previous view with a flip animation.
Now I have the facility to delete data from array I have picked from first view and passed to this one.
Now I have a condition that there is a button on the righthand side on the navigationBar on whose controller the previous view was pushed.
Now that button needs to be disabled until there r atleast X number of elements in the array.
so while I am adding data In my previous view, I keep check on the array and as soon it crosses the required count , I enable the button.
Now in the other view which is a TableView which has been brought in with animation,
Whenever I delete data I need to disable the button again when it goes below the number X.
How can I access the navigationBar's button in this subview's controller ?
shall I set the first view Controller as delegate in the next one ?
If your viewController is inside UINavigationViewController, you can set navigationBar buttons with self.navigationItem.leftBarButtonItem and self.navigationItem.rightBarButtonItem.
try using superView proprty or loop through all the pushed ViewController and check if it is previous VC. Then make the button enabled or disabled
My opinion is you can create a uinavigationController object in your subview and assign it from your parent view(Where you have the navigation controller object). You can then access the navigation controller in the subview.
Related
I have a UIViewController, VC with some elements on it, 2 of which are UITextFields. There is a button that, upon the users touch, presents a new controller CustomAlertViewController, VCAlert over the current VC with a modal presentation style of UIModalPresentationOverCurrentContext.
In this VCAlert I have 3 text fields.
When I press the tab key on my bluetooth keyboard, initially it only toggles through the 2 text fields on VC, even after presenting VCAlert, which is now the top-most presented view controller.
This is the important bit:
AFTER I tap one of the 3 fields on VCAlert, pressing the
tab button correctly toggles through the 3 fields on the top-most view
controller, now ignoring the input fields in the view controller underneath.
Is there a way to tell VCAlert (the top-most presented view controller) to listen for the tab button events, and NOT the parent controller any longer (until of course VCAlert is dismissed)?
I would like to accomplish this without having to remove the delegates from the 2 VC text fields, OR removing them from the view.
CODE:
The code is extremely straightforward... so it will be limited.
Each UITextView has its delegate registered to the respective view controller. The VCAlert controller is presented in the following way:
// Here, self is the VC, and alertViewController is VCAlert
[self presentViewController:alertViewController animated:NO completion:^{
// Do absolutely nothing here like usual
}];
FYI:
I have tried called becomeFirstResponder on one of the text fields in VCAlert then immediately called resignFirstResponder, but it doesn't make the tab bar toggle them - it still toggles the fields on the view controller below.
At the bottom of the Detail View Controller of a Split View Controller, I have added a Toolbar in the Storyboard. I have added three Bar Button Items in this Toolbar. Each Bar Button Item is hooked to its IBOutlet in the private interface of the Details View Controller, and also hooked to its IBAction implementation in the same controller, for example:- (IBAction)shouldPresentView:(UIBarButtonItem *)sender
The main view contains:
A Webview.
A small rectancgle view at the bottom of the screen, below the webview, created and added programmatically, and containing various buttons. All the buttons stay operational.
When touching any of the Bar Button Items, the button is temporary highlighted, but none of the IBAction methods is triggered (a NSLog() statement in every method is never executed).
After searching and reading equivalent topics, I went through several solutions:
I added manually the Details View Controller as the delegate of the Toolbar in the View Did Load method of the Details View Controller.
I emptied the cache of the Derived Data of the Product.
I checked that every IBOutlet has an address and is not nil.
I tried to add an action SEL manually in the View Did Load method for every Bar Button Item.
I removed the rectangle bottom view to be sure that it was not interfering with the responder chain.
I added a Bar Button Item in the Navigation Bar to check if the same problem occurs: no, the Bar Button Item fires the IBAction method.
Any help would be appreciated.
Developing with iOS 7 SDK in Xcode 5.0.2
The issue was coming from a Tap Gesture that I added to the main view to collect touches on the web view. So the touch on the Bar Button Items was probably captured somewhere by the main view before reaching the UIButtonBarItem. I changed the target of the Tap Gesture to the web view – more logical – and the issue has been solved.
I have an app with a navigation controller that does a segue to another view controller and then checks for the presence of an object in viewDidLoad (that may or may not exist). It then updates the name of a barButtonItem if the object exists. The problem is I can see the button expanding to accommodate the new name as the segue occurs.
How can I make this button change before the view is loaded so this jumping button effect is not seen? Shouldn't changes made in viewDidLoad not be seen until after viewDidAppear?
I am new to iOS and confused about the right way to implement UIPickerView.
I have a UITableView (the list of which is populated by XML File). Now I want to implement an option to trim down that list (say, show only type X or type Y). Now the confusion is, should I implement the PickerView in TableView itself, or make a new segue to show PickerView.
I tried implementing the first one but couldn't get it working.
A picker view wouldn't really fit inside a table view. You should have a button on the navigation bar or toolbar on your table view controller which presents a modal view controller holding your picker view.
This would then feed the selected value back to the table view controller (via a custom delegate protocol method, or similar) and the table view can filter its rows.
I have 2 tabbars in my tabbar controller. I am currently in the second tabbar, after I click on a 'done' button, the tabbar controller needs to switch to the first tab and auto refresh the tableview in it.
I am able to execute on the first part
//Switch to the first tab's view
self.tabBarController.selectedViewController
= [self.tabBarController.viewControllers objectAtIndex:0];
However I need some advise on how to refresh the first view's tableview immediately after the switch is made. Any advise is appreciated.
EDIT: Updated requirement
Note: I do not want the view in the tabbar to reload everytime someone clicks on the tab. The reload should only happen in tab 1's tableview when
1) User is in tab 2
2) User clicks on 'Done button' in tab 2
3) App switches to tab 1 + Reloads the tableview in tab 1
Rationale is that the user will update some information in tab 2 which can only be viewed in tab 1. I want the user to be able to view the updated info immediately after switching to tab 1.
You could just do [tableView reloadData] in the first view's viewDidAppear: method?
EDIT: Editing to add additional data.
General caveat here, Apple tends to frown upon having custom UI Patterns like this. I'm not sure what your app is trying to do here, but you should mostly stick with switching tabs only if the user explicitly clicks on that tab. Have you looked at modal view controllers if you want to present a screen and get some data back, instead of having it in a tab bar?
If not, I guess you could have a solution where the first tab is a delegate of the second tab. When the button is clicked, you could call [delegate doneBtnClicked:] so the control shifts to the first tab. In that function, you could use the setSelectedIndex: to your current tab and call reloadData: on the table view.
You can send NSNotification after
pressing done button on second tab
and handle this notification on first tab controller.
So, create a DONE Button as a UIBarButtonItem, and in it's IBAction, do the following.
For reloading the tableView for the view in the first tab, put that tableView as that class' property , and reference the class like #class class1 , and create an object as a property class1 *object1 for View1 (Tab1) in the class for View2 (Tab2), and access the array1 using object1 like
[class1.object1.array1 reloadData];
And for bringing the view to tab one, use
self.tabBarController.selectedIndex = 0;
Thats pretty much it !
Alternatively you can also use a singleton class for this purpose.