我已使用this来实现我的custom alert view
。对于alert view
,我添加了UITextfield
来输入一些详细信息。我的问题是如何在按下按钮时从警报视图中获取输入文本。
我的实现就像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];
}
当在表格视图行中单击按钮时,此警报视图会显示。任何人都可以告诉我如何在这里获取文本字段值?
谢谢
答案 0 :(得分:0)
您的问题的解决方案就像您要访问的UITextField
的全局声明一样简单。
UITextField
。AlertView
方法中的createDemoView
。buttonTappedDone
方法中,检查UITextField
中的文本,如果不为空,则可以从那里使用。