[英]getting textfield values from customized alert view
I have used this to implement my custom alert view
. 我用它来实现我的custom alert view
。 To my alert view
, I have included a UITextfield
to input some details. 对于我的alert view
,我包括一个UITextfield
来输入一些详细信息。 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 ? 谁能告诉我如何在这里采用textfield值?
thank you 谢谢
The solution to your problem is as simple as a global declaration of the UITextField
that you want to access. 解决问题的方法很简单,就是您要访问的UITextField
的全局声明。
UITextField
globally. 全局声明UITextField
。 AlertView
in your createDemoView
method. Alloc初始化文本字段,并将其添加到createDemoView
方法中的AlertView
中。 buttonTappedDone
method, check for the text in the UITextField
and if not null, you can use it from there. 在buttonTappedDone
方法中,检查UITextField
的文本,如果不为null,则可以从那里使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.