0

I don't understand why this would occur, so I'm looking for someone to help explain the reason.

I did this override in my code to fix an issue I was having with blue bar button items on a blue nav bar when in Messages via an Activity share action (all other button tint is white):

extension MFMessageComposeViewController {
  public override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
  }
}

Now, when I try to share text and an NSURL via UIActivityViewController, it no longer displays the text and url in the Messages text area. When I comment out the above code, it works again and displays the text and link correctly (but of course with blue bar button items on a blue nav bar).

What would cause this to happen?

Justin Stanley
  • 390
  • 3
  • 11

2 Answers2

1

In an extension,override will make original function of that class invalid.But inherit won't.(If you called super....)

let vc: MFMessageComposeViewController = …
vc.navigationController?.navigationBar.tintColor = UIColor.whiteColor()

And then present it.

Lumialxk
  • 6,239
  • 6
  • 24
  • 47
  • In another words,super in extension is super,but in inherit is self. – Lumialxk Feb 01 '16 at 02:17
  • Thanks. The issue I have then is that I can't actually call MFMessageComposeViewController because the Action menu calls it, so I can't actually tell it to be an inherited version. Is there any other way I can implement the revised navbar tint? – Justin Stanley Feb 01 '16 at 02:22
  • @JustinStanley Updated my answer. – Lumialxk Feb 01 '16 at 02:26
  • So I guess what is happening is when Messages does stuff via the Action Menu, it must have some tasks it does from within viewWillAppear() that are invalidated by my override. Maybe if I put it in something like viewDidLayoutSubviews() it might work ok... – Justin Stanley Feb 01 '16 at 02:26
  • the problem is nowhere can I do that since it's the ActionViewController that instantiating and calls Messages. :/ – Justin Stanley Feb 01 '16 at 02:27
  • and P.S. That's how I handled it for when I needed to do the same thing for Mail, but I was calling Mail myself for a Send Feedback button in my app. This works differently. – Justin Stanley Feb 01 '16 at 02:29
  • 1
    @JustinStanley override in extension is always dangerous because you don't know Apple did anything in that function.And Apple dislikes dev do this. – Lumialxk Feb 01 '16 at 02:30
  • @JustinStanley try to override viewWillAppear. I explored for a little while but got no better way. – Lumialxk Feb 01 '16 at 02:52
  • So how would I override it if everything is being controlled my ActionViewController? – Justin Stanley Feb 01 '16 at 02:55
  • but isn't that what I did in my original question? – Justin Stanley Feb 01 '16 at 03:01
  • 1
    @JustinStanley Year,it maybe causes some bugs but you must do like this. – Lumialxk Feb 01 '16 at 03:04
1

Here is what has worked for me in the past:

// Changes Bar Color //
UINavigationBar.appearance().barTintColor = UIColor.blueColor()
// Changes Bar Button Color //
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.classForCoder()]).tintColor = UIColor.whiteColor()
// Set Up & Show ActivityController //    
let activityController = UIActivityViewController(activityItems: ["YOUR TEXT HERE"], applicationActivities: nil)
self.presentViewController(activityController, animated: true, completion: nil)

Hope this helps!

ZGski
  • 2,398
  • 1
  • 21
  • 34
  • See I've already got those exact first two lines in my AppDelegate yet the Messages and Mail Action items still don't have white barbuttonitems! It's driving me nuts, I tell you! lol. Everything else is exactly as it should be. – Justin Stanley Feb 01 '16 at 03:42
  • 1
    Wow, this seems like a bug. I moved the first two lines into `didFinishLaunchingWithOptions()` , and everything works fine. I would definitely suggest cleaning your project, uninstalling and re-installing your application on the device, and quitting and restarting Xcode. – ZGski Feb 01 '16 at 03:46
  • I'll give it a shot! – Justin Stanley Feb 01 '16 at 03:48
  • actually...it's not just me. I have people who are using my app say that it's an issue as well. So I think it's actually an issue on Apple's end. :/ – Justin Stanley Feb 02 '16 at 02:18