Runtime error on Did End On Exit in iPhone application - iphone

Does anyone know why im getting runtime error when i click on return button on iphone keyboard. I need to hide keyboard after done editing values to UITextField. So i assigned Did End On Exit to IBAction and the IBAction code below
-(IBAction)FinishEditing:(id)sender
{
[folderName resignFirstResponder];
}
When running ma project i facing a runtime error and the variable values shown below
argv char ** 0xbffff58c
*argv char * 0xbffff6b8
**argv char '/'
Console Value
(lldb)
Any idea to overcome this issue??

According to your question you want to hide keyboard on return button click of keyboard. So there is no need to make any button action for this.. you can do that by UITextField delegate method. Add UITextFieldDelegate in ViewController.h file and then simply write below method in ViewController.m file :-
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
It would return on return button click of keyboard.

You can use the textfield delegate method to do the process .No need to pin the IBActions for this one use
– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:
refer this
and
This is a nice tutorial

Thanks guys for helping me. Finally i figure out my issue..
initially my code is like this
AddFolder *addButton = [[AddFolder alloc] initWithNibName:#"AddFolder" bundle:[NSBundle mainBundle]];
[self.view addSubview:addButton.view];
[addButton release];
And now ma code is like this
AddFolder *addButton = [[AddFolder alloc] initWithNibName:#"AddFolder" bundle:[NSBundle mainBundle]];
[self.view addSubview:addButton.view];
We dont need to release memory after adding a subview.

Related

How to go to another view by clicking on the textfield?

I have a simple question, how to connect a textfield to another Control view, if I click on the textfield, instead of show the keyboard it jump to another view
Thanks for answers
In the delegate method of the TextField, wich is textFieldShouldBeginEditing, add code that go from current View to another View.
Or you can use tap gasture recognizer on TextField to get the touch.
Here is the code:
create a TextFied in your IB and connect it to .h file
#interface ViewController : UIViewController<UITextFieldDelegate>
#property (strong, nonatomic) IBOutlet UITextField *firstTF;
And in .m file add this
#synthesize firstTF;
- (void)viewDidLoad
{
[super viewDidLoad];
firstTF.delegate= self;
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
secondViewController *ainfoController = [[secondViewController alloc] initWithNibName:#"secondViewController" bundle:nil];
[self presentModalViewController:ainfoController animated:YES];
return YES;
}
If you are adding the Textfield by code then,
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(x, y, width, height)];
textField.delegate = self;
[self.view addSubview:textField];
and add this method
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField{
// you can add the code for present a new viewController here
return NO;
}
make sure you have added UITextFieldDelegate in your .h file
I really don't get in why you need this but as a developer we do firmly believe to implement all scenarios, so in your case, you can achieve the same by following the any one beneath mentioned tacts:
1) In this approach, you need to override the textfieldshouldbegin delegate and use the navigate code for moving from one screen to another and don't forget to call resignFirstResponder here.
2) While in this second approach what you can do, just overlap a custom button(with neither image nor any text) and just on his click event method write your navigation code to move another screen.
Do that stuff, you'll get what you want and in case still you find any difficulty just shout over me.

UISearchBar becomeFirstResponder returns 0, but have valid reference to UISearchBar

I have a UIViewController with UISearchBar (and SearchDisplayController) along with a UITableView. When navigating to this view controller, I want to auto-focus on the UISearchBar (bring up the keyboard with focus on the text field in the search bar). Everything says to use
[searchBar becomeFirstResponder]
(assuming searchBar is an outlet to the UISearchBar)
I put this at the end of viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
BOOL did = [searchBar becomeFirstResponder];
[searchBar setText:#"donkey"];
}
Variable did is 0 (and focus doesn't happen), but the search bar's text is successfully changed to donkey.
What am I doing wrong?
I'm using iOS 5 with ARC and latest Xcode (4.3.2).
Got it working. Just had to put it in viewDidAppear instead of viewDidLoad or viewWillAppear.
add your code to -(void)viewDidAppear;
This worked for me:
[window makeKeyAndVisible]
we must ensure the METHOD becomeFirstResponder be performed on mainThread
so make it like :
[xxx performSelectorOnMainThread:#selector(becomeFirstResponder) withObject:nil waitUntilDone:NO];

UITextView.text doesn't work

hi i'm studying iOS programming.
i have a trouble to use UITextView.
i made a project and open viewController.xib
i dragged in UISearchBar, UITextView and UILabel
and my viewController is followed UISearchBarDelegate
i want to change textView.text's contents but it doesn't.
here's my code.
-(void)viewDidLoad
{
[super viewDidLoad];
self.mySearchbar.delegate = self;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
self.myLabel.text = #"hoho";
self.myTextview.text = #"hoho";
}
when i clicked search bar and typing any character and return,
myLabel's text is set to hoho.
but myTextview.text doesn't set. no effect.
why is that?? i'm confused.. please help me
Did you link up the Outlet in Interface Builder? In IB, click File's Owner, select Outlets on the right pane, link myTextview to the UITextview you put on the view?
Also, since you are calling "self" I assume you created a property for myTextview as an IBOutlet in your .h file?
Are you setting(connecting) the delegate of UITextView as well. That might be the problem.
Try to set the TextView Color to black
[YourTextview setTextColor:[UIColor blackColor]];
Sometimes this helps.
As I recall, instead you should be using
[self.myLabel setText:#"hoho"];

Modal View Controllers appear behind Action Sheet

My modal view controllers are being shown behind my UIActionSheet, and my UIActionSheet is not getting dismissed. I am using:
[self presentModalViewController:composeTweetView animated:YES];
To present my modal view controller.
My action sheet is being shown from the tabBar:
[actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];
This code worked on iOS 4.0.
if (buttonIndex == 0) {
if (self.isLoggedIn) {
[FlurryAPI logEvent:#"ST_REPLY_CLICKED"];
composeTweetView.isDirectMessage = FALSE;
[self presentModalViewController:composeTweetView animated:YES];
[composeTweetView release];
}
else {
LoginViewController* loginView = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
loginView.delegate = self;
loginView.isPostingComment = TRUE;
self.isReply = TRUE;
[self presentModalViewController:loginView animated:YES];
[loginView release];
[composeTweetView release];
}
}
Summary:
I have a UIViewController that contains a UITabBar. I am presenting a UIActionSheet which has a few buttons that present a modal view controller. When the modal view controller is presented, the UIActionSheet should dismiss itself and the modal view should be on the top of the stack. The problem is, the UIActionSheet does not dismiss, and the modal view is loaded behind it. This problem did not occur up until iOS 4.2.1
Steps to Reproduce:
Create a TabBar project, setting
your Base SDK to iOS 4.2.1
Create a button or trigger to show a UIActionSheet
Allow one of the buttons in the UIActionSheet to present a modal view controller using the syntax: [actionSheet showFromTabBar:self.parentViewController.tabBarController.tabBar];
Expected Results:
1. The UIActionSheet should dismiss itself, and the modal view should appear in front
Actual Results:
1. The UIActionSheet does not get dismissed and the modal view appears behind it.
Regression:
This problem was not apparent prior to iOS 4.2.1
Notes:
I have tried other ways of displaying the UIActionSheet all of which don't work as intended:
//[actionSheet showInView:self.parentViewController.tabBarController.tabBar];
//[actionSheet showInView:[self.view window]];
//[actionSheet showInView:self.parentViewController.tabBarController.view];
//[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
In putting together a sample in order to reproduce your problem I took a look at the UIActionSheet delegate methods. I believe you can use:
actionSheet:didDismissWithButtonIndex:
instead of
actionSheet:clickedButtonAtIndex:
I haven't tested it, but I believe you still get the same button number and it doesn't fire until the actionsheet has disappeared from the view.
I don't understand your problem sorry but everything works great for me. I have tried the following code in Simulator and on 4.2.1 iPod Touch 4G (both worked)
- (IBAction)doit {
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:#"title" delegate:self cancelButtonTitle:#"not OK" destructiveButtonTitle:#"Absolutely" otherButtonTitles:nil];
[actionSheet showFromTabBar:self.tabBarController.tabBar];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)];
v.backgroundColor = [UIColor redColor];
[self.view addSubview:v];
[v release];
}
}
created the TabBar sample project
added button to firstView-nib and connected with the appropriate IBAction (have to name the FileOwner to FirstViewController)
set the delegate method in FirstViewController.h (<UIActionSheetDelegate>)
added the code above
//EDIT: ok I saw that you want to present it modally but even this works for me on 4.2.1
TMPController *tmp = [[TMPController alloc]initWithNibName:#"TMP" bundle:nil];
[self presentModalViewController:tmp animated:YES];
[tmp release];
maybe it works because I use self.tabBarController.tabBar, try that
Not sure if you have already resolved this. But I didn't see a clear answer above. I was having exactly the same problem as you. So in the end, it was an issue on my side, but what help me debug this was to add the actual action code in the method
actionSheet:didDismissWithButtonIndex:
as suggested by Matthew.
This proved that the view was actually dismissed. That's when I realized that I put the UIActionSheet alloc in my viewWillAppear method. So each time the view appears it re-creates the action sheet.
This seems weird as the SDK Documentation states:
actionSheet:clickedButtonAtIndex:
…
The receiver is automatically dismissed after this method is invoked.
I can think of 3 possibilities why it may not disappear:
The main runloop (main thread!) which handles the animations and display stuff is not called. Do you work something heavy in your main thread like synchronous networking calls? (note the word "after" in the SDK text)
Somehow you schedule to show the action sheet multiple times
You display the same view controller instance modally that is already somewhere below the current view on the view stack.
I just wrote a quick sample app to test this out and it worked just as I expected (i.e., I couldn't repro your issue). It was a little different in that I didn't do a TabBar application but I'm still hopeful this helps. What I did with the UIActionSheet was to show it like this: [actionSheet showInView:self.view]. Maybe that will work?
Sorry for the rushed answer, I was on my way out when this caught my eye. :)
I have also faced problems like this with iOS 4.2.
I think you should try with the following steps:
Create a separate method for the code you want to be executed on clicking the actionsheet button. suppose the method is -(void)presentModalView{}
2.Now in the - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex method,Call the presentModalView{} method for the clicked button index like this:
if(buttonIndex==0)
{
[self performSelector:#selector(presentModalView) withObject:nil afterDelay:0.3];
}
3.You can also try by different delay time.
Hope it helps..
I had the same issue calling MailComposeView from AlertBox/ActionSheet caused the MailCompseView to come behind invisible screen.
I solved it by calling dismissWithClickedButtonIndex:animated: in the actionSheet button handler.
The problem has been resolved in iOS5.

Removing a UIView

So I have a view controller called MainViewController with a button which when I press this code is called:
NewViewController *newViewController;
newViewController = [[NewViewController alloc] initWithNibName:#"NewView" bundle:nil];
[self.navigationController.view addSubview:newViewController.view];
[newViewController release];
This brings in the new view which works great. However, how can I remove this view from a button within it? In an application I wrote a while ago I simply created a method in MainViewController called RemoveView and within the XIB file for NewViewController I selected FirstResponder and then RemoveView for the button. This works but I can not replicate it in my new project and don't really understand how it works anyway!
It's not the remove view code I'm looking for, more the way of getting the method to call from another class.
If anyone could help me that would be great! :)
Thanks
Drawing the line in Interface Builder does the same thing as calling
[theButton addTarget:theController action:#selector(theAction) forControlEvents:UIControlEventTouchUpInside];
theAction needs to be a method that is defined with a type of IBAction.
For your situation, in your NewViewController.h, declare
- (IBAction)removeView;
Then in NewViewController.m:
- (void)removeView
{
[self.view removeFromSuperview];
}
In your newView.xib file, you should be able to drag a line from the UIButton that you've drawn to your File's Owner, and select the removeView action.