Setting the Frame of an Object Programatically Has No Effect - ios5

I need to me a UIAlertView viewer than the standard size.
This is what I'm trying so far:
UIAlertView *addNewDevice = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Add New Device", "Title for add new device") message:nil delegate:self cancelButtonTitle:NSLocalizedString(#"CANCEL", #"Cancel Button") otherButtonTitles:NSLocalizedString(#"OK", "OK"), nil];
addNewDevice.frame = CGRectMake(addNewDevice.frame.origin.x, addNewDevice.frame.origin.y, addNewDevice.frame.size.width, 500);
[addNewDevice show];
Yes I'm aware a width of 500 points is too big, but I merely put that value there to test and my UIAlertView is not modifying its size.
Admittedly I don't know much about dealing with objects programatically, but I have spent the afternoon reading about them with no luck regarding this. Any help will be appreciated.

Try putting the frame line after the show line.
[addNewDevice show];
addNewDevice.frame = CGRectMake(addNewDevice.frame.origin.x, addNewDevice.frame.origin.y, addNewDevice.frame.size.width, 500);

Related

Custom UIalertView in iOS5

Do anywho know a custom UIAlertView class what is working in iOS5 ?
I'm looking for a class like TSAlertView, with that I will able to put 2 buttons stacked into alert.
( http://cocoacontrols.com/platforms/ios/controls/tsalertview )
Thanx for help.
UIAlertView in iOS 5 has UIAlertViewStyles
UIAlertViewStyleDefault
UIAlertViewStyleSecureTextInput
UIAlertViewStylePlainTextInput
UIAlertViewStyleLoginAndPasswordInput
EDIT Sorry for misunderstanding your problem. The alert view shown in the linked page is extremely easy to reproduce. Here's what I came up with:
I implemented this with a category for convenience but you could easily just implement it elsewhere. Basically what you do is add a cancel button and then hide it. That way there are three buttons as far as the alert view is concerned and it does not place the two visible buttons side by side. The category implementation is as follows:
-(void)showWithCutCancelButton{
// Make sure alert view will look right
if (self.cancelButtonIndex == -1 || self.numberOfButtons < 3) return;
self.clipsToBounds = YES; // or else cancel button will still be visible
[self show];
// Shrink height to leave cancel button outside
self.bounds = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - 64);
}
Then you show this by calling:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Hello" message:#"Message here" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Option1", #"Option2", nil];
[alert showWithCutCancelButton];

how to resize alertview in iphone

Hi i want to show my alertview message on large font so user can read proper when i run but it show me as small only how to resie font of message according to ipad i try this but it not working for me what to in my code help me on this
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Flight Search" message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
//UIAlertView* alert = [[[UIAlertView alloc] init]initWithFrame:CGRectMake(100,0,340,200)];// message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
//[alert setTitle:#"Flight Search"];
//[alert setCenter:CGPointMake(160.0f, 240.0f)];
//alert.frame = CGRectMake( 100, 0, 600, 500 );
//[alert setNeedsLayout];
[alert show];
alert.frame = CGRectMake( 0, 0, 340, 200 );
//alert.frame = CGRectMake( 100, 0, 600, 250 );
[alert release];
}
else {
UIAlertView* alert=[[UIAlertView alloc] initWithTitle:#"Flight Search" message:#"Please select both outbound and inbound flights" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
From the UIAlertView docs:
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
You can't modify it.
Check this question/response to find out how to make a custom alert view:
default UIALertView cannot be modified as per Apple's Documentation , Instead make your own Custom AlertView
UIAlertView have UITextView inside with two or single button. So that's why it can expends over vertically but not Horizontally according to input. If you need to expand it ,increase message contents but you r not able to change font size.
You can do any thing with the default alert view. It will re size according to the text you have written. if you want to, then you need to create your own custom alert view. Check the link. put custom image and buttons and then you will be able to re size it.

Can't get UIAlertView to work

I have a problem with UIAlertView i do not understand. I cannot get it to work. I have changed the code during test so the UIAlertView should hit directly when pressing the button.
I have tested with breakpoint/debugger and what is happening when i press the button is that the first line that it stops at is "otherButtonTitles:nil];".
I did test the piece of code in an other part of the app and it worked.
I have no idea what i am doing wrong.
- (IBAction)startNewGame_Button:(id)sender {
UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:#"VARNING"
message:#"Ingen spelare är vald!\n \n Välj spelare och försök igen!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[noPlayersAlert show];
[noPlayersAlert release];
...
}
==============UPDATE=====================
When i copy this code to another button it works??
Here it is in one line, tested that with the same result:
UIAlertView *noPlayersAlert = [[UIAlertView alloc] initWithTitle:#"VARNING" message:#"Ingen spelare är vald!\n \n Välj spelare och försök igen!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
==============UPDATE #2==================
Problem solved, even if i do not understand the reason, as i removed an "exit(0)" i had far below the UIAlertView during the testing.
Thanks to all of you who answered :)
Why have you not set the delegate to self?
How do you know the line stops at otherButtonTitles:nil? If there is a crash log, post the results of it.
You must set delegate a value, because it needs to call dissWith, delegate method of the alertView. So please set:
delegate: self

UIActionSheet long list behavior changed in 4.2?

I am seeing some changed behavior in iOS 4.2 with UIActionSheet. I can't find anything in Apple's developer docs or forums about it, so I'm not sure how to resolve it.
In my list app, I present the user with an actionsheet from which she can pick the list she wants to load on startup. Obviously that means there will be a variable number of items, and the control handles it fine. Until about 7 items, it shows all items as buttons. Once it crosses that threshold, it puts the items into a scroll view to choose from. Until 4.2, it included the Cancel button in that scrolling list. In 4.2, it now seems to be separating the Cancel control, leaving it as a button while putting the rest of the items into the scroll view. The problem is that it appears that it keeps the Cancel item in the list of button indices, so that when I inspect the buttonTitleAtIndex:buttonIndex in either clickedButtonAtIndex: or didDismissWithButtonIndex:, the first item returns "Cancel", then the other item titles are off by 1. Clicking the Cancel button also returns "Cancel".
Anyone else experienced this and have a suggestion for how to handle it? Again, this worked fine in 3.0, 3.1, 4.0, and 4.1.
Here's the relevant code I'm using:
- (IBAction)popupDefaultListActionSheet {
UIActionSheet *popup = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (List *l in allActiveLists) { // allActiveLists defined elsewhere
[popup addButtonWithTitle:[l label]];
}
popup.actionSheetStyle = UIActionSheetStyleBlackOpaque;
popup.tag = 23;
[popup becomeFirstResponder];
[popup showInView:[self.view.window.subviews objectAtIndex:0]];
[popup release];
}
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
DLOG(#"AppSettingsVC.actionSheet didDismissWithButtonIndex: %d", buttonIndex);
NSString *defaultListName = [actionSheet buttonTitleAtIndex:buttonIndex];
DLOG(#"chosen default list was: %#", defaultListName);
}
Try adding the cancel button dynamically at the end instead of setting it up initially:
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"My Action Sheet"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
for (I32 i = 0; i < itemCount; i++) {
[actionSheet addButtonWithTitle:itemText];
}
[actionSheet addButtonWithTitle:#"Cancel"];
[actionSheet setCancelButtonIndex:itemCount];
Seems to work correctly in iOS 4.2 for us at least.

UIAlertView not displaying complete message

I have the following function to display error messages to user. But it does not seem to show the complete message. It will display upto certain characters followed by ....
How can I make it show the entire message?
(void) showAlert:(NSString*)title forMessage:(NSString*) body
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:body delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
There is a way.
When you present your alert, you can just implement this method:
- (void)willPresentAlertView:(UIAlertView *)alertView {
alertView.frame = CGRectMake(alertView.frame.origin.x, alertView.frame.origin.y -50
,alertView.frame.size.width, 300);
}
Adjust the height to fit your need. It will look something like this:
If you need to move the button around, you can just add new lines (\n) to your message, and it will move the button down.
As mentioned by sudo rm -rf, UIAlertView has a limit.
You can try creating your own "alert" that doesn't clip by creating a view controller and showing it using presentModalViewController:animated:.