Note that there are some explanatory texts on larger screens.

plurals
  1. POAlertView defined outside ViewController
    primarykey
    data
    text
    <p>For easier code reading I decided to create AlertView as new object. I created class AlertViews as subclass of NSObject. I created 2 UIAlertView - one with single text Field and other as plain UIAlertView. To test it, I wanted to input text in UIAlertView click OK and see NSLog. </p> <p>AlertViews.h </p> <pre><code>@interface AlertViews: NSobject { UIAlertView *addSomethingAlertView; UIAlertView * showSomethingAV; } @property (nonatomic, retain) UIAlertView *addSomethingAlertView; @property (nonatomic, retain) UIAlertView *showSomethingAV; -(void)InitializeAddSomethingAlertView; -(void)InitializeShowSomethingAV; </code></pre> <p>AlertViews.m</p> <pre><code>@implementation @synthesize addSomethingAlertView = _addSomethingAlertView; @synthesize showSomethingAV = _showSomethingAV; -(void)initializeAddSomethingAlertView { addSomethingAlertView = [[UIAlertView alloc] initWithTitle:@"Something" message:@"something" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitle:@"OK", nil]; addsomethingAlertViewStyle = UIAlertViewStylePlainTextInput; [[addSomethingAlertView textFieldAtIndex:0] setDelegate: self]; [[addSomethingAlertView textFieldAtIndex:0] setKeyboardType: UIKeyboardTypeDecimalPad]; [[addSomethingAlertView textFieldAtIndex:0] becomeFirstResponder]; [addSomethingAlertView show]; } -(void)InitializeShowSomethingAV { showSomethingAV = [[UIAlertView alloc] initWithTitle:@"show" message:@"show" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitle:@"show", nil]; [showSomethingAV show]; @end </code></pre> <p>ViewController.h</p> <pre><code>#import"AlertViews.h" @interface ViewController: UIViewController &lt;UIAlertViewDelegate&gt; { AlertViews *newAlert; AlertViews *showAlert; } @property (nonatomic, retain) AlertViews *newAlert; @property (nonatomic, retain) AlertViews *newAlert; -(IBAction)adding:(id)sender; -(IBAction)showing:(id)sender; </code></pre> <p>ViewController.m</p> <pre><code>@implementation @synthesize newAlert = _newAlert; @synthesize showAlert = _showAlert; -(IBAction)adding:(id)sender { [self.newAlert = [[AlertViews alloc] init]; [self.newAlert initializeAddSomethingAlertView]; } -(IBAction)showing:(id)sender { [self.showAlert = [[AlertViews alloc] init]; [self.showAlert initializeshowSomethingAV]; @end </code></pre> <p>I tried to implement this code in ViewController.m</p> <pre><code>-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { if (addsomethingAlertView) {if (buttonIndex == 1) { NSLog(@"adding"); } if (showSomethingAV) {if (buttonIndex == 1) {NSLog(@"showing"); } } </code></pre> <p>However, I do not get any LOG.</p> <p>Also, how can I use text entered in AlertView Text Field?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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