It seems like I am not able to change the title on the navigation bar, which gets set to the Subject of the email (in this case "My Subject"). In this case I'd like to get rid of the title, either using an empty string as title or rendering the title invisible.
MFMailComposeViewController *mfViewController = [[MFMailComposeViewController alloc] init];
mfViewController.mailComposeDelegate = self;
[mfViewController setSubject:[NSString stringWithFormat:#"My Subject"]];
[mfViewController setMessageBody:[self emailBody] isHTML:NO];
[mfViewController setTitle:#""];
where u have presented ModalViewController
[self presentModalViewController:controller animated:YES]; // Existing line
add
[[[[controller viewControllers] lastObject] navigationItem] setTitle:#"Set the title"];
I believe this is some kind of protection came with iOS4.
It is clearly stated here that you MUST NOT change the interface provided by Apple.
http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.
i have searched the forums and some have got their app rejected, so i guess u should refrain urself from doing this.
hope it helps. happy coding :)
Related
I am trying to manually push a view controller within my iOS 8 app. I have designed it in the Main.storyboard and i have already attached on it an specific identifier.
The code i am using is:
CustomViewController *vc =
[self.storyboard instantiateViewControllerWithIdentifier:#"CustomViewController"];
vc.customField1 = self.customField1;
vc.customField2 = self.customField2;
[self.navigationController pushViewController:vc animated:YES];
but that causes the app's freeze. It does not spit out any logs or something, so I cannot understand what might be wrong.
Can you help me a bit here?
Thank in advance
Do not do these two lines:
vc.customField1 = self.customField1;
vc.customField2 = self.customField2;
The problem here is that you're assigning one text field to be another text field (actually, you're making a text field reference refer to a completely different text field). Instead, copy the contents (e.g. the text) of the fields from your parent view controller to fields that already live in your new CustomViewController:
vc.customField1.text = self.customField1.text;
vc.customField2.text = self.customField2.text;
I'm thinking what is happening here is that the app is hanging when the new CustomViewController appears because it's trying to access fields in the now hidden / pushed-away parent view controller.
How to use UIKeyboardAppearanceDark with SLComposeViewController?
The SLComposeViewController class presents a view to the user to compose a post for supported social networking services.
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[self presentViewController:controller
animated:YES
completion:nil];
SLComposeViewController Class Reference
Ugly!
This is how the light keyboard looks with a dark background:
Mockup!
This is how the dark keyboard looks with a dark background:
I have tried a few methods. The only way that I found working is to customize the entire ComposeViewController. I also believe it is the only possible way.
I found an open source project calls REComposeViewController and I customized it to have UIKeyboardAppearanceDark by default. I have uploaded to Github you can download and play with it.
Project: https://github.com/voyage11/SLComposeViewControllerWithBlackKeyboard
Attached Screen shot:-
After carefully understanding the problem you are facing and doing some R&D, I'm suggest you to go for Custom ComposeViewController, because you can't change the keyboardAppearance of ComposeViewController's keyboard.
For implementing Customize ComposeViewController follow the below steps:
1) Made some custom view like SLComposeViewController's View.
2) On the post button you need to implement the logic in SLComposeViewControllerResultDone
[_shareComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result)
{
switch (result)
{
case SLComposeViewControllerResultCancelled:
break;
case SLComposeViewControllerResultDone:
{
}
break;
default:
break;
}
}];
3) And when you wants to show your custom view, make sure that the textView you are using in the custom view must be assign keyboardAppearance's property to UIKeyboardAppearanceDark
self.yourTextField.keyboardAppearance = UIKeyboardAppearanceDark;
Below is the picture of customize view, that I implemented in a my recent project.
Hopefully it will helps you.
This is a private class, thus your only chance is to traverse view hierarchy after SLComposeViewController has loaded its view, find corresponding UITextField and set keyboardAppearance to UIKeyboardAppearanceDark
Update scratch that, even traversing view hierarchy would be tricky (impossible) since it uses XPC and remote views.
You can use this code
self.yourTextField.keyboardAppearance = UIKeyboardAppearanceDark;
I am instantiating a UIImagePicker like so:
self.picker = [[UIImagePickerController alloc] init];
[self.picker setDelegate:self];
[self.picker UIImagePickerControllerSourceTypePhotoLibrary];
[myVC presentViewController:self.picker animated:YES completion:nil];
And for some reason, it doesn't ask me for permission to view my images (on device, it is magically already allowed access (checked in Privacy settings)) and the images are blank. Yes, you heard correctly. Blank. They're completely white. However when I tap in a location where a image should be present, it shows the image in the editor view and displays the image.
Interestingly enough, this issue had nothing to do with NavigationControllers, UIImages/ImageViews or even ViewControllers. I had a category on NSDictionary that overrode objectForKeyedSubscript. I guess users images are stored or retrieved in a Dictionary and when they tried to index into it for the UIImage, it failed somehow. Or maybe pulled a path that was nil.
The moral of this story is, BEWARE the CATEGORY.
So I've seen previous questions similar to this but they were of no help. I've read Apple's documentation too but I could not understand where I've gone wrong. AFAIK I did everything logically, but when I click on my done button on an UItoolbar overlay, the button can be pushed but it does not do anything. This obviously means it fails to acknowledge the written code. But how?
I want to bring up the .nib of "TableViewController" when a done button is clicked on my UIToolBar. But the below isn't allowing the click to bring up a new view. How do I rectify this? Please show me where I went wrong and what should be replaced and why.
-(void)doneButtonPressed {
TableViewController *UIView = [[TableViewController alloc]
initWithNibName:#"TableViewController" bundle:nil];
UIView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:UIView animated:YES];
[UIView release];
}
Whoa, you've got some bizarre stuff going on here. In your first line, you're allocating and initiating the TableViewController instance correctly, but you're not giving that instance a unique name. You're naming it with another class's name, which is bound to stir up problems. In fact, I'm surprised it didn't through an error.
Try the following instead:
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:#"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
Now, your TableViewController instance has a unique name that is referenced throughout the rest of the method. Just to be clear--UIView is another class name, and therefore cannot be used as the name of an instance of an object.
EDIT: Additionally, be sure to add your button's selector doneButtonPressed: to your .h file of its view controller. Also, if you like you can toss an NSLog() call in the beginning of the function just to be sure it isn't (or perhaps is) being called.
Something to check when button actions aren't firing is that you've got the appropriate selector. If you've followed the selector correctly. Make sure you aren't using a selector of
#selector(doneButtonPressed:)
which would look for a function like:-
- (void) doneButtonPressed:(id) sender
For your member function, you need
#selector (doneButtonPressed)
The debugger is your friend here. Start with a breakpoint to make sure your function is being called.
If you're getting into the function, then The Kraken's answer is the next thing to check.
There is no restriction on using a class name as a variable name whatsoever. Although you should change it because its confusing and doesnt follow iOS coding conventions.
"Button can be pushed but doesnt do anything", is the selector even being called?
-(void)doneButtonPressed
Show how you created the UIBarButtonItem to verify that you provided the right selector in the init method or that you connected the button directly in interface builder (which it doesnt look like since you didnt use the (IBAction) return signature.
I'm creating an interactive book for learning languages. It has reading, quiz and some simple game. The content of each chapter is an HTML file. The book allows the user to learn about 300 words that exist in the text. Earch word was enclosed in a link like this: < a href="word">word< /a> when the user touch the link, a modal view appears with the translation and information about that word.
This is the code I'm using to get the link:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
// currentWord is the word in the link
self.currentWord = [[request URL] lastPathComponent];
// okToCatchLinks is a BOOL that I use to avoid showing the modalview when the page
// is loaded for the first time.
if (okToCatchLinks){
NSLog(#"Ok to catch links!");
WordViewController *viewController = [[WordViewController alloc] initWithNibName:#"WordViewController" bundle:nil]
// I did my homework creating the delegate protocol to dismiss the modal view.
viewController.delegate = self;
// This is a label in the modalview showing the word in the HTML link.
viewController.labelTitle = self.currentWord;
// Create a Navigation controller to add the "DONE" dismiss button
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:viewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
// show the navigation controller modally
[self presentModalViewController:navController animated:YES];
// Clean up resources
[navController release];
[viewController release];
}
okToCatchLinks = YES;
return YES;
}
With this code I will get the selected word in a string variable. Then I search that word in the DB using CoreData.
The HTML is UTF-8 encoded. I have to be able to search for that word in different languages. So if the user click on the word (日本語) or (résumé) I have to be able to find it in the DB.
For the data store I converted an CSV file to a .sqlite file.
I wonder if there is a better way to do this. Personally I don't like to use < a href=""> to get the link, but I couldn't find any other way to get the current word in a link. Also performing the search of that word in the DB is not clean, because I'm not using any UID for each row. I just compare the string holding the word with the words in the corresponding column of the DB.
Is there a more efficient way to do this?
To resume: Having a list of words, mark those words in the HTML so the user can touch and retrieve information about that word from a DB.
Some observations:
UIDs: As long as your words are unique, you can use that column as the primary key without using a separate UID. Actually, Core Data will create one for you anyway, so you can use objectWithID to retrieve your word.
HTML Links: Your solution with UIWebView, HTML files and links seems feasible to me. However, you could of course also use a UITextView and handle the selections programmatically, working with NSRange. That would perhaps be more complicated, but also more "native".
Delegate: You only need a delegate if you want to pass information back to the view that first presented the model view controller (too much homework! ;-)). Just dismiss it from within with
[self dismissModalViewControllerAnimated:YES];