I thought, and I may be wrong, without doing anything, the titleView of UINavigationController default to the title of the UIViewController.
Mine is not the case and I wonder why?
I set the title of the UIViewController in the story board to #"Nearby". I confirm that it's indeed the title in viewDidLoad
- (void)viewDidLoad
{
PO(self.title);
PO(self.navigationController.title);
Produce
self.title: Nearby
self.navigationController.title: (null)
I think I can programatically force my way and set the titleView to a UILabel with my title but I am not sure that would be the right way to do it.
I wonder why self.navigationController.title is not automatically set to self.title? If so when should it be set and where?
By the way, I added this line:
self.navigationController.title=self.title;
That doesn't help.
Update: Changing the NavigationItem Title Works. But that's awkward. Also how do I change that programatically?
Related
I try to implement a view that has on the top a view with dynamic height and below a UICollectionView in a storyboard.
As long as I layout that directly in one ViewController everything works fine.
When the top view is managed by a separate ViewController and embedded, I always run into autolayout problems:
SizingSample[53440:11697282] [LayoutConstraints] Unable to simultaneously satisfy constraints. (
"<NSLayoutConstraint:0x6000030cc690 UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'.bottom == SizingSample.DynamicSizeView:0x7fda024197b0.bottom + 3 (active)>",
"<NSLayoutConstraint:0x6000030cc960 SizingSample.DynamicSizeView:0x7fda024197b0.top == UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'.top + 20 (active)>",
"<NSLayoutConstraint:0x6000030c52c0 'UIView-Encapsulated-Layout-Height' UIView:0x7fda024195d0.height == 0 (active)>",
"<NSLayoutConstraint:0x6000030cc870 'UIViewSafeAreaLayoutGuide-bottom' V:[UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide']-(0)-| (active, names: '|':UIView:0x7fda024195d0 )>",
"<NSLayoutConstraint:0x6000030cc7d0 'UIViewSafeAreaLayoutGuide-top' V:|-(0)-[UILayoutGuide:0x600002af9180'UIViewSafeAreaLayoutGuide'] (active, names: '|':UIView:0x7fda024195d0 )>"
)
IMO the 'UIView-Encapsulated-Layout-Height' constraint breaks everything, but I haven't found any way to prevent it.
A striped down sample can be found at https://github.com/tengelmeier/viewcontroller-embedding-problem.git
How can I autolayout a view honoring the dynamic size of an embedded view(..controller)?
Because ios Automatically Apply Fixed Frame set while embedding ContainerController.you have to tell don’t translate autoresizing mask into LayoutConstraint.
You can do this by setting following Property in ContainerViewController(destination Controller) ViewdidLoad method.
view.translatesAutoresizingMaskIntoConstraints = false
I want to add tabs in the navigation title like below. Anyone could tell me the method to implement this.
I use swift2 and IOS9.
You can set any kind of UIView object to your navigationItem as a titleView
self.navigationItem.titleView = segmentedControl;
here segmentedControl maybe UISegmentedControl object.
I try to make a photo-app that can read Qr-Codes with the ZXing-Library.
Most parts work but now somehow my LowLagPhotoCapture doesn't return anything useful:
var photoProperties = MediaProperties.ImageEncodingProperties.createJpeg();
mediaCaptureMgr.prepareLowLagPhotoCaptureAsync(photoProperties)
.done(function (_lowLagPhotoCapture) {
lowLagPhotoCapture = _lowLagPhotoCapture;
lowLagPhotoCapture.captureAsync()
.done(function (capturedPhoto) {
...
The MediaCaptureMgr works, I see a preview of the cam on the screen. But now I need to make a photo. The usual PhotoCapture didn't work with JavaScript and so I found this solution.
Somehow the lowLagPhotoCapture.captureAsync() crashes saying that lowLagPhotoCapture is empty. lowLagPhotoCapture is defined outside of this class because I need it later. But even if I pass the variable directly to the new method it fails =/
Any ideas what might go wrong with this?
Edit:
Okay, after every Async-operation I had a following nameless function and one exitOnError-function that was calles every time. If I remove thatv exitOnError-function out of .done(complete, error), it exits in the same place. But if I set a breakpoint on .captureAsync it goes 1-2 steps further, creates an ImageStream and exits somewhere there. Why the different behaviour with and without the breakpoint?
I have successfully added a rightBarButtonItem to my navigationBar, but I would prefer to only have the code to do so show up once rather than once per type of ViewController. Here's my current setup:
-->TVC
|
NVC--->TVC--->TVC--->VC
So far I've subclassed UITableViewController and moved my code for adding the button into my subclass. All 3 of my TableViewControllers are set to that subclass and it works perfectly.
However now I need my lone ViewController to also show the button, but I don't know how to accomplish this without duplicating the code from my TVC subclass. Is subclassing the right answer or do I need a different approach?
Edits:
#CarlVeazey - Sure, I call it from the viewDidLoad function.
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"BETA" style:UIBarButtonItemStylePlain target:self action:#selector(betaPressed)];
Do a pull-up refactor into a UIViewController category. If your project already has one, just add this code there, otherwise press cmd-N in Xcode to create a new file and choose "Objective-C Category" and enter UIViewController in the "Category On" field.
In the interface add this method declaration:
- (void)onfConfigureRightNavigationBarButton;
And in the implementation add this method implementation:
- (void)onfConfigureRightNavigationBarButton
{
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"BETA"
style:UIBarButtonItemStylePlain
target:self
action:#selector(betaPressed)];
}
Then in any UIViewController subclass you can import your category header and call this method. You may also wish to add to your category an empty implementation of betaPressed:.
BTW, ONF is the prefix I use for non-work coding so use whatever prefix already is in your project, or none at all if you're not concerned with category name collisions.
I'm building an very simple application and I would like to reduce the coding lines in it, and I would like to that by using one or two functions instead of 20.
The app displays 10 buttons. Each button has two buttons to display, both with the same action (sending an email) but each button has a different identity so it also has different email content. It works fine if I do a function for each button, but I know it's possible to simplify that, I just don't know how.
Can someone point me in the right direction? This is what I'm doing right now in my methods:
MFMailComposeViewController *controller1 = [[MFMailComposeViewController alloc] init];
controller1.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[controller1 setToRecipients:[NSArray arrayWithObjects: #"dev#company.com", nil]];
[controller1 setSubject:#"Button 1"];
[controller1 setMessageBody:#"The second option form button 1 was selected" isHTML:NO];
[self presentModalViewController:controller1 animated:YES];
}
[controller1 release];
Set a unique tag (see the tag property) for each button and check the tag of the sender in your one -sendEmail: method. All your buttons call that one method.