I developed app for iOS and i trie catch the event in a button, that button is in a xib and i create a method when touch up inside.
and i present de view the following form
DetailNoticiaController *detail = [[DetailNoticiaController alloc] init];
[self.view addSubview:detail.view];
detail.view contain the button, when the button is pressed, the app crashed and not show the error.
The problem is that detail deallocates as you don't save it somewhere. You may try code below:
DetailNoticiaController *detail = [[DetailNoticiaController alloc] init];
[self addChildViewController:detail];
[self.view addSubview:detail.view];
Helpful link - "Creating Custom Container View Controllers"
Related
I create a window in which I take custom view. Here is my PROJECT.
Credetials : modijecky#gmail.com, Password : 2
Just sign in through credetials and click on second option in side bar and then click on login.
Here my code to add xib view in my viewcontroller of my main view
- (IBAction)watchClicked:(id)sender {
//id animator = [[ContactUsVC alloc] init];
ContactUsVC* vc = [[ContactUsVC alloc] initWithNibName:#"ContactUsVC" bundle:nil];
vc.view.frame = self.view_main.bounds;
[self.custom_view addSubview:vc.view];
[self.view_main setEnabled:NO];
}
I put a button on ContactUsVC and when I click app crashed. I dont understand why simple click is not happen.
Here is Error
Exception Name: NSInvalidArgumentException
Description: -[_NSImageAuxiliary btn_click_phone_no:]: unrecognized selector sent to instance 0x6080002c10a0
User Info: (null)
Place breakpoint before this line
ContactUsVC* vc = [[ContactUsVC alloc] initWithNibName:#"ContactUsVC" bundle:nil];
And check whether button's action is executed or not.By crash description it seems Image Button. Have you place any image on button?
In tableViewController i want to create a plus push button at "run time" in viewDidLoad of tableViewController to trigger another view.
I tried it as follows:
- (void)viewDidLoad
{
[super viewDidLoad];
//
// create Button in Navigation
//
self.VC_AddToDoItem = [[GRF_VC_Add_To_Do_Item alloc] init];
[self.navigationController pushViewController:self.VC_AddToDoItem animated:NO];
UIBarButtonItem *bt_Plus = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self.VC_AddToDoItem action:#selector(add:)];
self.navigationItem.rightBarButtonItem = bt_Plus;
}
The result is that the table view is not displayed. Instead the view is displayed with link back to table view. If i press this link, table view is displayed. If i then press plus button then i get a crash.
What could be the problem?
Update:
I added the add method now in GRF_VC_Add_To_Do_Item. Crash is now gone. Method add is called. But i don't know what to do in this method to show the view, therefore this method is empty at the moment. If i press the "+" button, nothing happens. What call is necessary in add method to display view GRF_VC_Add_To_Do_Item?
I am developing a library for a iOS app that will authenticate the users on the basis of the credential entered by them.
What I am doing is that, from a view controller say TestViewController I am setting a new view controller LoginScreenViewController on top of TestViewController when user taps a button by using the following code.
LoginScreenViewController * LoginScreen = [[LoginScreenViewController alloc] initWithNibName:nil bundle:nil];
[self.view addSubview:LoginScreen.view];
This LoginScreenViewController contains a Cancel button, on which I want to remove the LoginScreenViewController. For this I am using following code
[self.view removeFromSuperview];
the problem is when I am executing this code, my app is crashing.
Since my LoginScreenViewController is defined by the Library, I want it to be independent of the caller's implementation.
EDIT:
In LoginScreenViewController.m I have used following code to add an event handler to the cancel button.
[button addTarget:self action:#selector(CancelButtonHandler:) forControlEvents:UIControlEventTouchUpInside];
The app is crashing when I am tapping the Cancel button. Even if the CancelButtonHandler does not contain any line of code.
You are trying to remove wrong view. To remove LoginScreen view do:
[LoginScreen.view removeFromSuperview];
My ipad project is master-detail view based. There is a button on detail view's toolbar, when user tap on the button, it popup a popover view to show four buttons (as menu). Three of buttons' actions are like the following (the three buttons show three different model form sheets):
- (void) showOnlineSgf
{
NSLog(#"showOnlineSgf");
TGOOnlineSgfViewController *dlg =
[[TGOOnlineSgfViewController alloc] initWithNibName:#"TGOOnlineSgfViewController"
bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:dlg];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:nav animated:YES completion:nil];
dlg = nil;
nav = nil;
}
The other button's action is to show a MFMailComposeViewController. Code is like the following:
- (void) emailCurrentGame
{
NSLog(#"email current game");
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
picker = nil;
}
The weird behavior is that when I tap the button what should execute showOnlineSgf(), but emailCurrentGame() is actually executed. When I set a breakpoint in showOnlineSgf(), it's hit, and step by step, each statement in showOnlineSgf() is executed. But the result on screen is a MFMainComposeViewController shows up.
I know this question is hard to answer. Any idea is appreciated.
Check your outlet connection of your UIButton that triggers showOnlineSgf. Most likely you copy pasted your UIButton in Interface Builder, which causes it to copy its assigned action as well. Then you've connected your other action, resulting in your UIButton having two actions.
To resolve the problem, simply disconnect your UIButton that triggers showOnlineSgf from the emailCurrentGame action.
Sounds like you copy pasted in the interface builder an already connected button. Check if the button has more than one action assigned.
I'm attempting to embed an editable UITextView inside a UIPopoverController, with... strange results. The steps I've taken are:
Create a custom UIViewController class, and create a .xib file with that controller with a UITextView inside it.
When the UI action that should bring up the controller occurs (touch up inside), I instantiate the controller and its view from the .xib file.
I create a new UIPopoverController, with the view controller I just instantiated as the content view.
I present it with presentPopoverFromRect:inView:permittedArrowDirections:animated:
Here's some example code:
- (void)noteButtonPressed:(id)sender {
self.noteview = [[MyTextPopupViewController alloc] initWithNibName:#"MyTextPopupViewController" bundle:nil ];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:self.noteview];
self.popover = popoverController;
self.popover.delegate = self;
[self.popover presentPopoverFromRect:((UIView*)sender).frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
Then, inside MyTextPopupViewController, I make sure the the text view is the first responder to bring up the keyboard:
- (void)viewDidAppear:(BOOL)animated {
[self.view becomeFirstResponder];
[super viewDidAppear:animated];
}
And that all works... right until it doesn't. Sometimes, it works perfectly; other times, either immediately or after a few keystrokes, the application crashes by exiting the main event loop (!). No exception is thrown (at least not that the lldb catches), but the application simply stops, both on the simulator and on hardware.
Any thoughts? Has anyone gotten this working successfully, or knows for sure that it does not?
I think the UIPopoverController instance needs to be a property in your code.