Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS dismiss model view form custom keyboard with input view
    text
    copied!<p>i have a navigation controller that present a modal view with textview </p> <p>i have also setting a custom input view (custom keyboard with number buttons and enter button) </p> <p>for that textview</p> <p>the number's buttons work fine but the enter button not working ( i went to dismiss the modal view with enter button)</p> <p>am using a delegate to do this but the delegate is always nil</p> <pre><code>inputView.h typedef enum ActionTag { ActionEnter = 0, ActionDivide, ActionMultiply, ActionSubtract, ActionAdd } ActionTag; @protocol InputViewDelegate &lt;NSObject,UIInputViewAudioFeedback&gt; - (void)dismissv:(ActionTag)tag; @end @interface InputView : UITextView { UIView *inputView; id &lt;InputViewDelegate&gt; ivDelegate; } @property (nonatomic,weak) id &lt;InputViewDelegate&gt; delegate; - (IBAction)takeInputFromTitle:(id)sender; - (IBAction)doDelete:(id)sender; - (IBAction)doTaggedAction:(id)sender; @end inputView.m #import "InputView.h" @implementation InputView - (BOOL) enableInputClicksWhenVisible { return YES; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } - (UIView *)inputView { if (!inputView) { NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CKeybroad" owner:self options:nil]; NSLog(@"loaded objects from nib: %@", objects); inputView = [objects objectAtIndex:0]; } return inputView; } - (IBAction)takeInputFromTitle:(id)sender { //[[UIDevice currentDevice] playInputClick]; self.text = [self.text stringByReplacingCharactersInRange:self.selectedRange withString:((UIButton *)sender).currentTitle]; // amount=self.text; } - (IBAction)doDelete:(id)sender { NSRange r = self.selectedRange; if (r.length &gt; 0) { // the user has highlighted some text, fall through to delete it } else { // there's just an insertion point if (r.location == 0) { // cursor is at the beginning, forget about it. return; } else { r.location -= 1; r.length = 1; } } // self.text = [self.text stringByReplacingCharactersInRange:r withString:@""]; self.text=@""; r.length = 0; self.selectedRange = r; } - (IBAction)doTaggedAction:(id)sender { ActionTag tag = [sender tag]; [ivDelegate dismissv:tag]; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end cashView.h import &lt;UIKit/UIKit.h&gt; #import "InputView.h" @protocol ModalViewControllerDelegate &lt;NSObject&gt; - (void)didDismissModalView; @end @interface cash_view : UIViewController &lt;InputViewDelegate&gt; { id &lt;ModalViewControllerDelegate&gt; delegate; UINavigationBar *navigationBar; IBOutlet InputView *inputView; IBOutlet UILabel *amount; } @property (nonatomic, retain) IBOutlet UINavigationBar *navigationBar; @property (nonatomic,retain) IBOutlet UILabel *amount; @property (nonatomic, retain) id &lt;ModalViewControllerDelegate&gt; delegate; - (void)closeModalViewController; -(IBAction)changelabel:(id)sender; -(IBAction)dismissView:(id)sender; @end cashView.m #import "cash_view.h" @implementation cash_view @synthesize navigationBar; @synthesize amount; @synthesize delegate; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { self.title = @"Cash Due"; } return self; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } #pragma mark - View lifecycle - (void)viewDidLoad { [super viewDidLoad]; [inputView becomeFirstResponder]; inputView.delegate=self; amount.text=@"00.00"; // Do any additional setup after loading the view from its nib. [self.navigationBar setItems:[NSArray arrayWithObject:self.navigationItem]]; UIBarButtonItem * closeButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonSystemItemCancel target:self action:@selector(closeModalViewController)]; self.navigationItem.rightBarButtonItem = closeButton; navigationBar.barStyle = UIBarStyleBlack; } - (void)closeModalViewController { [self dismissModalViewControllerAnimated:YES]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES; } - (void)doEnter { [self dismissModalViewControllerAnimated:YES]; } - (void)textViewDidChange:(UITextView *)textView { int length=inputView.text.length; if(length==0) amount.text=@"0,00"; else amount.text=inputView.text; } - (void) doArithmetic { // inputView.text = [decimalFormatter stringFromNumber:result]; //inputView.text=@"1"; self.amount.text=@"1"; } -(IBAction)changelabel:(id)sender{ // [self dismissModalViewControllerAnimated:YES]; [delegate didDismissModalView]; } - (void)doDecimalArithmetic:(SEL)method { } #pragma mark InputViewDelegate - (void)dismissv:(ActionTag)tag { switch (tag) { case ActionEnter: [self doEnter]; break; case ActionDivide: [self doDecimalArithmetic:@selector(decimalNumberByDividingBy:)]; break; case ActionMultiply: [self doDecimalArithmetic:@selector(decimalNumberByMultiplyingBy:)]; break; case ActionSubtract: [self doDecimalArithmetic:@selector(decimalNumberBySubtracting:)]; break; case ActionAdd: [self doDecimalArithmetic:@selector(decimalNumberByAdding:)]; break; default: break; } } // Done button clicked - (IBAction)dismissView:(id)sender { // Call the delegate to dismiss the modal view [delegate didDismissModalView]; } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload