I'm trying to display custom menu items similar to copy-paste menu item, is there any way I can do this?
I never do this, but there is a sample code named 'CopyPasteTile'
It seems that the important point is the UIResponderStandardEditActions protocol, and the - (BOOL)canPerformAction:(SEL)action withSender:(id)sender method of UIResponder
Related
So I have a visual cue (PNG rectangle lines) that pops up when taking a picture for this test app I’m doing.
So I remove the visual cue in the did finish picking media delegate method and/or the didcancel method as well. But I can’t find info on a delegate method for inbetween. Is there one? If there isn’t, is there a way to handle using a visual cue during image taking but not during the deciding “phase”?
I've looked at the Apple Docs but can't find anything so far. I'm trying to be better as far as attention to detail but I still struggle so my apologies if I didn't see it
I don't think there's code necessary to show so I can't show sample code.
No, the only delegate methods are imagePickerController(_:didFinishPickingMediaWithInfo:) and imagePickerControllerDidCancel(_:).
If you want to customize the user interface during picture taking, you can take a few approaches.
First, use the cameraOverlayView property to customize the UI.
Second, note that the UIImagePickerController is itself a UINavigationController. You can therefore set its delegate and respond to navigationController(_:willShow:animated:) to be notified when the user is about to move between view controllers. You could implement logic here to show, hide, or otherwise adjust your custom UI.
Can someone please tell me how to disable the keyboard in a Text View? Whenever I click on words, the keyboard pops up and I am able to manipulate my original text. I just want it to be selectable, so you can copy, paste. I prefer this to be disabled for the whole app. If someone could tell me how and where to implement this I would really appreciate it.
ThX
I think it's in the inspector isn't it?
For disabling using code, use the below given code.
Inherit UITextFieldDelegate protocol In your view controller add the text
#interface YourViewController () <UITextViewDelegate>
In viewDidLoad set yourself as a delegate:
yourUITextView.delegate = self;
Implement the delegate method below:
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
return NO;
}
Is it possible to call a method when a tab bar icon is touched, even if its already the selected icon? I want to make it remove a sub view when touched if the subview is showing.
I'm sure there must be a way to do this because I see it in other apps, but I cannot find any documentation on it.
From Apple Documentation for UITabBarDelegate :
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
Sent to the delegate when the user selects a tab bar item. (required)
As you noticed I think, and as stated by Apple docs, this message is sent only when a tab is selected
An important note, there is already a (not-documented?) default UIKit behavior of tapping a selected tab bar button :
If the tab contains a UINavigationViewController it will send to it a popToRootViewControllerAnimated: message. You can check this on any iOS application.
So beware before overriding this default (and user expected) behavior, which is, generally, a bad idea.
Apple has probably hidden what you want to do in its UIKit API, on purpose.
But if you want anyway does this, here are some ideas:
Small, but not easy hack: Once the tabBar has been displayed, recursively browse its .subviews tree to find (I expect, to be confirmed) UIButtons inherited classes (=private UITabBarButtons or something like) to add your target/selector pairs on TouchUp event (you might have to remove default behavior first, which might be tricky)
Worst solution, but might be the only one: Do not use UITabBar, but a custom class. I'm pretty sure there are ready-to-use open source components that mimics UITabBar, but sorry, I never used/searched one.
You can have delegates for the UITabbarcontroller,
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;
Also please go through this document: UITabBarController delegate protocol
i need some help:
i have several views (view xib): login, sign up, settings, and so on.
i have created a project, added a tab controller and the tabs are working fine.
The problem is that: we have 2 sign up 'ways' and my boss want them in two different tabs. The code is almost equal, so my idea is:
instead of having 2 different views with copied & pasted code, i would like to create a general sign up view and just 'fire' the signUp_method1 if the user presses the first tab, also if the user presses the second tab i will fire the signUp_method2. the question is how should i do this?.
also, i'm worried that i will not be able to customize the view depending of the action: i have to show 2 different fields and labels according to the sign up way. i have been looking for some way, i read about viewDidLoad and actually i'm using it for initialization but that does not solve the problem.
Perhaps i should not use tab controller, so, if you have suggestions i'm happy to read them.
Thanks for reading.
Use the UITabBar delegate methods. You need to make sure the view that the tab bar is in implements the "UITabBarDelegate" in the class header.
This method might do the trick:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
// You can put logic in here to check on what item was pressed and fire the different methods depending on what you put.
if ([[item title] isEqualToString:#"Libraries"]) {
NSLog(#"Pressed on libraries tab!!");
} else if ([[item title] isEqualToString:#"Search"]) {
NSLog(#"Pressed on search tab!!");
}
}
As long as you have your components linked up in IB to your controller properly, you should be able to programmatically manipulate them as needed.
I am having quite a issue trying to change the cut/copy/paste behavior of the UITextView.
What I want to achieve is: detect when the user has pasted some text into the UITextView. When I detect this I will then check the data and do my thing.
According to the documents, I found out about UIResponder.
So I created an simple class that inherits UITextView.
in the .m file I create 1 function called.
-(void) paste:(id)sender{
NSLog(#"paste button was pressed do something");
}
But for some reason it never seems to fire. I could get the select statement working and tracing data.
-(void) select:(id)sender
1. Is this the correct way to detect Paste in a UITextView?
2. Right now I am tracking buy how many Characters UITextView changes and if its greater than one char then I suspect that it could be a paste operation. But since the iPhone can autocomplete words eg Wedn (goes to Wednesday) its possibly not a paste operation.
In Interface Builder, I selected my textView in my NIB file, and selected its "Class Identity" to my nearly created class before and I know that this file was working as a subclass but it just would not respond to the Paste event.
thanks.
UITextView has a view that handles the cut, copy, paste. It's UIWebDocumentView. So if UITextView is the first responder, UIWebDocumentView will get it first instead of your implementation. I would like to overwrite these functions so this is very frustrating.
Same thing happens to me too. Select (and copy sometimes) gets called but paste never.
I have simulated the behavior using textViewDidChange where I always verify the difference between the current text and the previous one. If there are more letters different and the text.length is bigger than it must have been pasted.
Hope Apple will fix this.
In case somebody still needs short and easy solution I'll share mine. I use wonderfull NSObject+REResponder category from REKit project. The solution is as easy as this:
- (void)hookMessageTextFieldPasteAction
{
void (^textFieldDidPasteBlock)(id receiver, id sender) = ^(id receiver, id sender)
{
NSLog(#"paste hook");
};
[self.messageTextField respondsToSelector:#selector(paste:) withKey:nil usingBlock:textFieldDidPasteBlock];
}
Yes your above code for paste is correct according to Apple's Documentation which refers to it here.
- (void)paste:(id)sender
I suspect you are implementing it in the wrong file. You should be implementing it in a file that is part of the 1st Responder chain. Have you subclassed the UITextView or are you using a vanilla one in your ViewController?
Hmmm I think the problem is that you may need to make your UITextView subclass become the delegate in order for the delegate method to work, because it's not by the looks of things. I'll try to find how i did that before.
Okay think i found it. I think you need to do this on your subclassed UITextField class:
#interface mySpecialTextFieldClass : NSObject <UITextFieldDelegate>
{
}
Adding that onto the end should work, give it a try!
What it does is makes your subclass become an object of a type that the delegate can send a notification to...it's polymorphism, unless someone wants to correct me here :)
One last thing to try John, in the ViewController which contains the IBOutlet to the UITextView, try calling this method on the instance of the UITextView:
[myUITextView setDelegate:self];
Just to throw something completely random in there try setting it to become first responder.
[myUITextView becomeFirstResponder];
This is called programming in the dark kiddies! And is a very bad way to program, but I admit I do it and sometimes it pays off :P lol.