Getting content from custom UITextfields in an UIAlertview - iphone

Got the following code:
-(void)addGrade {
UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:#"Text" message:#"\n \n \n" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Add", nil];
// Textfield1
UITextField *utextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
[utextfield becomeFirstResponder];
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
utextfield.leftView = paddingView;
utextfield.leftViewMode = UITextFieldViewModeAlways;
utextfield.placeholder = #"Subject";
[utextfield setBackgroundColor:[UIColor whiteColor]];
utextfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[alertview addSubview:utextfield];
// Textfield2
UITextField *ptextfield = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 90.0, 25.0)];
ptextfield.placeholder = #"Another Subject";
ptextfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
ptextfield.textAlignment = NSTextAlignmentCenter;
[ptextfield setBackgroundColor:[UIColor whiteColor]];
[alertview addSubview:ptextfield];
// Textfield3
UITextField *ctextfield = [[UITextField alloc] initWithFrame:CGRectMake(161.0, 85.0, 27.0, 25.0)];
ctextfield.placeholder = #"3";
[ctextfield setBackgroundColor:[UIColor whiteColor]];
ctextfield.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
ctextfield.textAlignment = NSTextAlignmentCenter;
[alertview addSubview:ctextfield];
// Label1
UILabel *telt = [[UILabel alloc] initWithFrame:CGRectMake(121.0, 85.0, 40.0, 25.0)];
telt.text = #"Text";
telt.textColor = [UIColor whiteColor];
telt.backgroundColor = [UIColor clearColor];
[alertview addSubview:telt];
// Label2
UILabel *keermee = [[UILabel alloc] initWithFrame:CGRectMake(199.0, 85.0, 100.0, 25.0)];
keermee.text = #"more text";
keermee.textColor = [UIColor whiteColor];
keermee.backgroundColor = [UIColor clearColor];
[alertview addSubview:keermee];
[alertview show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if ([title isEqualToString:#"Add"])
{
UITextField *field = (UITextField *)[[alertView subviews] lastObject];
NSLog (#"%#", field.text);
}
}
This code makes 3 Textfields and 2 labels in an UIAlertView.
With UITextField *field = (UITextField *)[[alertView subviews] lastObject]; I got back "more text" which is true because you are asking about the last object.
Now is my question how to get the content of all the UITextfield not only the label?

for (UIView *view in [alertView subviews]){
if ([view isMemberOfClass:[UITextField class]]){
UITextField *textField = (UITextField *)view;
NSLog(#"%#", textField.text);
}
}

Assign tags and retrieve them with those.
myTextField.tag = 100;
Then to find it use this function:
myTextField = [view subviewWithTag: 100];

Related

How to delete label that created programmatically?

I am creating two label programmatically using this code..
-(void)addLabel:(id)sender
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
theDataObject.count = theDataObject.count+1;
NSLog(#"count is :%i",theDataObject.count);
if (theDataObject.count == 2) {
addLabel.enabled = NO;
}
if (theDataObject.count == 1) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
blabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
blabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
blabel.adjustsFontSizeToFitWidth = NO;
blabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
blabel.font = [UIFont boldSystemFontOfSize:18.0];
blabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
blabel.backgroundColor = [UIColor clearColor];
blabel.lineBreakMode = UILineBreakModeWordWrap;
blabel.numberOfLines = 10;
blabel.minimumFontSize = 8.;
blabel.adjustsFontSizeToFitWidth = YES;
[blabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
blabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(blabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[blabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[blabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:blabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:blabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
blabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = blabel;
labelResizableView.delegate = self;
labelResizableView.tag =2;
[self.view addSubview:labelResizableView];
}else if (theDataObject.count == 2) {
CGRect imageFrame = CGRectMake(10, 10, 150, 80);
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
clabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 35, 100, 100)];
clabel.text = #"Write here";
//alabel.text = self.newsAsset.title;
clabel.adjustsFontSizeToFitWidth = NO;
clabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
clabel.font = [UIFont boldSystemFontOfSize:18.0];
clabel.textColor = [UIColor blueColor];
// alabel.shadowColor = [UIColor whiteColor];
// alabel.shadowOffset = CGSizeMake(0, 1);
clabel.backgroundColor = [UIColor clearColor];
clabel.lineBreakMode = UILineBreakModeWordWrap;
clabel.numberOfLines = 10;
clabel.minimumFontSize = 8.;
clabel.adjustsFontSizeToFitWidth = YES;
[clabel sizeToFit];
labelResizableView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// enable touch delivery
clabel.userInteractionEnabled = YES;
//tao gasture recognizer for label
UITapGestureRecognizer *doubleTap =[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(clabelTap:)];
doubleTap.numberOfTapsRequired = 2;
[clabel addGestureRecognizer:doubleTap];
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:#selector(longPress:)];
[longPressGesture setMinimumPressDuration:1];
[clabel addGestureRecognizer:longPressGesture];
//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(296,9999);
CGSize expectedLabelSize = [greetString sizeWithFont:clabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:clabel.lineBreakMode];
//adjust the label the the new height.
CGRect newFrame = blabel.frame;
newFrame.size.height = expectedLabelSize.height+40;
newFrame.size.width = expectedLabelSize.width+40;
clabel.frame = newFrame;
labelResizableView.frame = newFrame;
labelResizableView.contentView = clabel;
labelResizableView.delegate = self;
labelResizableView.tag=3;
[self.view addSubview:labelResizableView];
}
}
And when user long press button than it will be deleted...
- (void)longPress:(UILongPressGestureRecognizer *)longPressGesture {
if (longPressGesture.state == UIGestureRecognizerStateEnded) {
//NSLog(#"Long press Ended");
// NSLog(#"blabel long pressed");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Delete Label" message:#"Want delete label" delegate:self cancelButtonTitle:#"No" otherButtonTitles:#"Yes",nil];
[alert show];
}
else {
//NSLog(#"Long press detected.");
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
[labelResizableView removeFromSuperview];
// NSLog(#"yes btn tapped");
}
}
but now when i longpree blabel than still clabel is deleted and it will never delete blabel.thanx in advance.
Use the Tag property to remove the labelResizableView.
-(void)addLabel:(id)sender
{
labelResizableView = [[UserResizableView alloc] initWithFrame:imageFrame];
labelResizableView.tag = 100;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Yes"])
{
ExampleAppDataObject* theDataObject = [self theAppDataObject];
if (theDataObject.count!=0) {
theDataObject.count = theDataObject.count-1;
}
addLabel.enabled = YES;
UILabel *tempLabel = (UILabel *)[self.view viewWithTag:100];
if(tempLabel)
[tempLabel removeFromSuperview];
}
}
hope this code help you :)
NSArray *subArray = [self.view subviews];
if([subArray count] != 0) {
for(int i = 0 ; i < [subArray count] ; i++) {
[[subArray objectAtIndex:i] removeFromSuperview];
}
}
To add control in your view:
[self.view addsubview:yourcontrolid];
ex:
[self.view addsubview:labelid];
To add control from your view:
[controlid removefromsuperview];
ex
[labelid removefromsuperview];
you are adding with :
[self.view addSubview:labelResizableView];
than remove it the labelResizableView, and release the clabel or blabel, whatever is in your case.
Maybe this gives an example
It is because your code
else if (theDataObject.count == 2) {
is calling and in this code you are adding
labelResizableView.contentView = clabel;
and then you are adding this to you view
[self.view addSubview:labelResizableView];
So when you are deleting labelResizableView
[labelResizableView removeFromSuperview];
So the result is you are adding labelResizableView 2 times and remove the labelResizableView which have clabel.

uialertview clickedButtonAtIndex message sent to deallocated instance

I created a UIAlertView that is in ViewDidLoad, as the following:
prompt = [[UIAlertView alloc] init];
prompt.title = #"تسجيل الدخول";
prompt.message = #"\n\n\n";
prompt.delegate = self;
[prompt addButtonWithTitle:#"الغاء"];
[prompt addButtonWithTitle:#"دخول"];
userNameTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
[userNameTxtField setBackgroundColor:[UIColor whiteColor]];
[userNameTxtField setPlaceholder:#"اسم المستخدم"];
[prompt addSubview:userNameTxtField];
passwordTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
[passwordTxtField setBackgroundColor:[UIColor whiteColor]];
[passwordTxtField setPlaceholder:#"كلمة المرور"];
[passwordTxtField setSecureTextEntry:YES];
[prompt addSubview:passwordTxtField];
[prompt show];
//[prompt release];
// set cursor and show keyboard
[userNameTxtField becomeFirstResponder];
and the clickedButtonAtIndex function is as following:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex ==0) {
NSLog(#"cancel");
}else {
NSLog(#"will login isA");
}
}
but when I click any buttons, I see the output and then the app crashes and gives me the following Exception:
[MaktabatyTableViewController respondsToSelector:]: message sent to deallocated instance 0x894cfa0
Any help ????
i have tried your code. your code working nicely .
-(void)viewDidLoad
{
UIAlertView *prompt = [[UIAlertView alloc] init];
prompt.title = #"تسجيل الدخول";
prompt.message = #"\n\n\n";
prompt.delegate = self;
[prompt addButtonWithTitle:#"الغاء"];
[prompt addButtonWithTitle:#"دخول"];
UITextField *userNameTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 50.0, 260.0, 25.0)];
[userNameTxtField setBackgroundColor:[UIColor whiteColor]];
[userNameTxtField setPlaceholder:#"اسم المستخدم"];
[prompt addSubview:userNameTxtField];
UITextField *passwordTxtField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 85.0, 260.0, 25.0)];
[passwordTxtField setBackgroundColor:[UIColor whiteColor]];
[passwordTxtField setPlaceholder:#"كلمة المرور"];
[passwordTxtField setSecureTextEntry:YES];
[prompt addSubview:passwordTxtField];
[prompt show];
//[prompt release];
// set cursor and show keyboard
[userNameTxtField becomeFirstResponder];
}

UIPIckerView issue

I have the code below in my app. I show a UIPickerView with options, and I have a TextView placed on the same UIViewController .
when the picker is shown with options, the rest of the view seems not in focus and only when I resign the uipicker, the entire view gets focus.
what is the problem here?
-(void)viewWillAppear:(BOOL)animated {
myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.frame = CGRectMake(0,35 , 320, 15);
[myActionSheet addSubview:pickerViewCountry];
[pickerViewCountry release];
closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:#"Done"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 27.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:#selector(hidePicker) forControlEvents:UIControlEventValueChanged];
[myActionSheet addSubview:closeButton];
[closeButton release];
[myActionSheet showInView:self.view];
[myActionSheet setBounds:CGRectMake(0, 0, 320, 250)];
UITextView *myTextView = [[UITextView alloc] init];
myTextView.frame = CGRectMake(100, 12, 210, 20);
myTextView.layer.borderWidth = 1.0f;
myTextView.layer.cornerRadius = 5;
myTextView.clipsToBounds = YES;
myTextView.layer.borderColor = [[UIColor grayColor] CGColor];
myTextView.text = #"some text";
[self.view addSubview:myTextView];
[myTextView sizeToFit];
}
You've placed your UIPickerView inside UIActionSheet. That's standart behavior for UIActionSheet. Try to use keyboardView instead like so:
UITextField* dummyTextField = [[UITextField alloc]initWithFrame:CGRectMake(0, -20, 10, 10)];//the point is to put it outside visible view
dummyTextField.inputView = pickerViewCountry;
[dummyTextField becomeFirstResponder];//call to appear
[dummyTextField resignFirstResponder];//call do disappear
and for the buttons you can use folloving:
dummyTextField.inputAccessoryView = <some toolbar with buttons or any other view>
Happy coding :)
I will suggest you one solution with custom View.
datePickerContainer is UIView:
//datepicker
datePickerContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 440, 310, 300)];
datePickerContainer.opaque = YES;
datePickerContainer.backgroundColor = [UIColor clearColor];
UIImageView *pickerNavBar = [[UIImageView alloc] init];
UIImage *barImage = [UIImage imageNamed:#"pickerbar.png"];
pickerNavBar.image = barImage;
pickerNavBar.frame = CGRectMake(0, 7, barImage.size.width, barImage.size.height);
[datePickerContainer addSubview:pickerNavBar];
[pickerNavBar release];
UIButton* blueButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[blueButton setTitle:#"Done" forState: UIControlStateNormal];
blueButton.frame = CGRectMake(255, 15, 55, 30);
[blueButton addTarget:self action:#selector(hidePickerViewContainer) forControlEvents:UIControlEventTouchUpInside];
[datePickerContainer addSubview:blueButton];
[blueButton release];
//UIPickerView Initialization code
UIPickerView *pickerViewCountry = [[UIPickerView alloc] init];
pickerViewCountry.showsSelectionIndicator = YES;
pickerViewCountry.dataSource = self;
pickerViewCountry.delegate = self;
pickerViewCountry.frame = CGRectMake(0,35 , 320, 15);
[datePickerContainer addSubview:pickerViewCountry];
[pickerViewCountry release];
//set container and release
[self.view addSubview: datePickerContainer];
[datePickerContainer release];
To show datePickerContainer UIVie use this code:
-(void)showPickerViewContainer{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGRect frameContainer = datePickerContainer.frame;
frameContainer.origin.y = 150.0f;
datePickerContainer.frame = frameContainer;
[UIView commitAnimations];
}
To handle done button and hide pickerView use this:
-(void)hidePickerViewContainer{
//here use you custom code to handle done action
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.4];
CGRect frameContainer = datePickerContainer.frame;
frameContainer.origin.y = 440.0f;
datePickerContainer.frame = frameContainer;
[UIView commitAnimations];
}
This is just a custom solution. Hope this help.
declare variable in header file
UIActionSheet *actionSheet;
NSString *pickerType;
Write Below code into your implementation file:
- (void)createActionSheet {
if (actionSheet == nil) {
// setup actionsheet to contain the UIPicker
actionSheet = [[UIActionSheet alloc] initWithTitle:#"Select"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(pickerDone:)];
[barItems addObject:doneBtn];
[doneBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
[actionSheet addSubview:pickerToolbar];
[pickerToolbar release];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 464)];
}
}
-(IBAction)BtnPressed:(id)sender
{
[self createActionSheet];
pickerType = #"picker";
select = NO;
UIPickerView *chPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 44.0, 0.0, 0.0)];
chPicker.dataSource = self;
chPicker.delegate = self;
chPicker.showsSelectionIndicator = YES;
[actionSheet addSubview:chPicker];
sessoTxt.text = [sessoArray objectAtIndex:0];
[chPicker release];
}
declare delegate methods
#pragma mark UIPickerViewDelegate Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
int count;
if ([pickerType isEqualToString:#"picker"])
count = [array count];
return count;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
NSString *string;
if ([pickerType isEqualToString:#"picker"])
string = [array objectAtIndex:row];
return string;
}
// Set the width of the component inside the picker
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 300;
}
// Item picked
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
select = YES;
if ([pickerType isEqualToString:#"picker"])
{
Txt.text = [array objectAtIndex:row];
}
}
- (void)pickerDone:(id)sender
{
if(select == NO)
{
if ([pickerType isEqualToString:#"picker"])
{
Txt.text = [array objectAtIndex:0];
}
}
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
[actionSheet release];
actionSheet = nil;
}
}

How to change UIAlertView text color?

I'm currently using http://kwigbo.com/post/318396305/iphone-sdk-custom-uialertview-background-color for my custom UIAlertView. Everything is working fine but I'm trying to change the title and message text colors and I would like to change the button color. Is there any way to do this? I've tried using:
UILabel *theTitle = [AlertView valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
but I can't get it to work. Any help would be appreciated. Thanks.
You just need to include UIAlertViewDelegate in your .h file and override this method in your .m file.
-(void)willPresentAlertView:(UIAlertView *)alertView{
UILabel *theTitle = [alertView valueForKey:#"_titleLabel"];
theTitle.font = [UIFont fontWithName:#"Copperplate" size:18];
[theTitle setTextColor:[UIColor whiteColor]];
UILabel *theBody = [alertView valueForKey:#"_bodyTextLabel"];
theBody.font = [UIFont fontWithName:#"Copperplate" size:15];
[theBody setTextColor:[UIColor whiteColor]];
}
Check to see if setTextColor is depricated.
I thought it was
theTitle.text.color = [UIColor redColor];
or you could use
[theTitle.text setColor:[UIColor redColor]];
Not totally sure on the second one, the first example should do the trick though.
By default functionality, you could not change alert view title and message but with the help of accessory view, you can achieve this functionality.
Try below method :
-(void)customAlertTitle:(NSString*)title message:(NSString*)message{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:nil cancelButtonTitle:#"NO" otherButtonTitles:#"YES", nil];
UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 80)];
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 270, 50)];
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.numberOfLines = 2;
titleLabel.textColor = [UIColor redColor];
titleLabel.textAlignment = NSTextAlignmentCenter;
[subView addSubview:titleLabel];
UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 270, 50)];
messageLabel.text = message;
messageLabel.font = [UIFont systemFontOfSize:18];
messageLabel.numberOfLines = 2;
messageLabel.textColor = [UIColor redColor];
messageLabel.textAlignment = NSTextAlignmentCenter;
[subView addSubview:messageLabel];
[alertView setValue:subView forKey:#"accessoryView"];
[alertView show];
}
The above code is working perfectly on latest XCode 8.3.1. Kindly comment if facing any problem.

actionSheet in iphone application

I am new to iphone.Is it possible to keep 3 textfields, 3 labels and 2 uibuttons in an actionsheet or alertview. Kindly give information.
Thanks in advance.
You can try this as:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"\n\n\n\n\n\n\n\n\n\n" message:#"" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK", nil];
UITextField *textfield1 = [[UITextField alloc] init];
textfield1.frame = CGRectMake(10.0, 30.0,260.0, 15.0);//set your frame as you required
textfield1.text=#"";
[textfield1 setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:textfield1];
[textfield2 release];
UITextField *textfield2 = [[UITextField alloc] init];
textfield2.frame = CGRectMake(10.0, 48.0,260.0, 15.0);//set your frame as you required
textfield2.text=#"";
[textfield2 setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:textfield2];
[textfield2 release];
UITextField *textfield3 = [[UITextField alloc] init];
textfield3.frame = CGRectMake(10.0, 65.0,260.0, 155.0);//set your frame as you required
textfield3.text=#"";
[textfield3 setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:textfield3];
[textfield3 release];
UIView *tempView = [[UIView alloc]initWithFrame:CGRectMake(10.0, 80.0, 260.0, 100.0)];//set your frame as you required
tempView.backgroundColor = [UIColor clearColor];
[alert addSubview:tempView];
UILabel *label1 = [[UILabel alloc]init];
label1.frame = CGRectMake(0, 5, 50, 15);//set your label frame here
label1.text = #"Enter text";
[tempView addSubView:label1];
[label1 release];
UILabel *label2 = [[UILabel alloc]init];
label2.frame = CGRectMake(0, 25, 50, 15);//set your label frame here
label2.text = #"Enter text";
[tempView addSubView:label2];
[label2 release];
UILabel *label3 = [[UILabel alloc]init];
label3.frame = CGRectMake(0, 45, 50, 15);//set your label frame here
label3.text = #"Enter text";
[tempView addSubView:label3];
[label3 release];
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = //set your button frame here
[tempView addSubview:button1];
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = //set your button frame here
[tempView addSubview:button2];
[tempView release];
[alert show];
[alert release];