Pregunta

I have used this to implement my custom alert view. To my alert view , I have included a UITextfield to input some details. My problem is how I get the input text from the alert view when the button is pressed.

My implementation is like thisL

- (UIView *)createDemoView
{


UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)];

//alertView.tag=2;

UILabel *rateLbl=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 45)];
rateLbl.backgroundColor=[UIColor clearColor];
rateLbl.font=[UIFont boldSystemFontOfSize:15];
rateLbl.text=@"Rate";

UILabel *cmntLable=[[UILabel alloc]initWithFrame:CGRectMake(10, 45, 290, 45)];
cmntLable.backgroundColor=[UIColor clearColor];
cmntLable.font=[UIFont boldSystemFontOfSize:15];
cmntLable.text=@"Add Comment";

UIImage *dot, *star;
dot = [UIImage imageNamed:@"dot.png"];
star = [UIImage imageNamed:@"star.png"];
JSFavStarControl *rating = [[JSFavStarControl alloc] initWithLocation:CGPointMake(150, 20) dotImage:dot starImage:star];
[rating addTarget:self action:@selector(updateRating:) forControlEvents:UIControlEventValueChanged];


UILabel *lblAlertTItle=[[UILabel alloc]initWithFrame:CGRectMake(5, 5, 290, 45)];
lblAlertTItle.backgroundColor=[UIColor clearColor];
lblAlertTItle.textAlignment=NSTextAlignmentCenter;
lblAlertTItle.font=[UIFont boldSystemFontOfSize:18];
lblAlertTItle.text=@"Choose your sharing option";


UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(150, 57, 100, 25)];
text.backgroundColor=[UIColor whiteColor];
//[demoView addSubview:lblAlertTItle];
[demoView addSubview:text];
[demoView addSubview:rating];
[demoView addSubview:rateLbl];
[demoView addSubview:cmntLable];


return demoView;

}

-(void)buttonTappedDone:(cellForDatePickCell*)cell{

NSString* appoinmentID =[NSString stringWithFormat:@"%@",cell.appoinment_Dtepick];
NSString* userID = [NSString stringWithFormat:@"%@",cell.USER_Dtepick];

NSDictionary* paras = [[NSDictionary alloc]initWithObjectsAndKeys:appoinmentID,@"appointmentId",userID,@"userId", nil];


jsonpaser* jpser = [[jsonpaser alloc]init];
//[self.indicator_process startAnimating];
[jpser getWebServiceResponce:@"MYYURL" :paras success:^(NSDictionary *responseObject)
 {
     //requestsF_date = responseObject;
     NSLog(@"Appoinment Completed :%@",responseObject);

     NSString* selecteDate = [ScheduleView getDate];

     NSString* prsonID =[LoginView getPersonID];

     NSDictionary* parms = [NSDictionary dictionaryWithObjectsAndKeys:prsonID,@"caregiverPersonId",selecteDate,@"selectedDate", nil];

     jsonpaser* jp = [[jsonpaser alloc]init];

     [jp getWebServiceResponce:@"MyUrl" :parms success:^(NSDictionary *responseObject)
      {

          requestsF_date = responseObject;
          NSLog(@"Done Clicked :%@",requestsF_date);
         [self.tableView reloadData];

      }];


 }];




// Here we need to pass a full frame
CustomIOS7AlertView *alertView = [[CustomIOS7AlertView alloc] init];

// Add some custom content to the alert view
[alertView setContainerView:[self createDemoView]];

// Modify the parameters
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"OK", @"Cancel", nil]];
[alertView setDelegate:self];

// You may use a Block, rather than a delegate.
[alertView setOnButtonTouchUpInside:^(CustomIOS7AlertView *alertView, int buttonIndex) {
    //NSLog(@"Block: Button at position %d is clicked on alertView %ld.", buttonIndex, (long)[alertView tag]);

    if (buttonIndex==0) {
        NSLog(@"button zero [ OK] clicked");
        // here i want to get the text box value


    }
    if (buttonIndex==1) {
         NSLog(@"button 1 [ Cancel] clicked");


    }





    [alertView close];
}];

[alertView setUseMotionEffects:true];

// And launch the dialog
[alertView show];

}

This alert view is popes up when a button clicked in a table view row. can anyone tell me how can i take the textfield value here ?

thank you

¿Fue útil?

Solución

The solution to your problem is as simple as a global declaration of the UITextField that you want to access.

  • Declare the UITextField globally.
  • Alloc init the text field and add it to the AlertView in your createDemoView method.
  • In the buttonTappedDone method, check for the text in the UITextField and if not null, you can use it from there.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top