changing UIActionSheetStyle makes no difference in iOS7? - ios

Is this some bug in iOS7? I took screenshots with
UIActionSheetStyleBlackOpaque,
UIActionSheetStyleBlackTranslucent,
UIActionSheetStyleAutomatic,
UIActionSheetStyleDefault.
It's all the same.
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#"Title" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:#"OK" otherButtonTitles:nil, nil];
[action setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; // changing enumerable here shows exactly same result
[action showInView:_controlsView];

As per this UIActionSheetStyle constants are unused in iOS 7.

Related

Placeholders for variables in UIAlertView?

I want a UIAlertView to warn the user if there are no items matching his/her chosen search criteria. My initial idea was to use this code:
if (aOiCount == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No instances of %#",self.thisSpec.activityOfInterest message:#"Please select an activity or Cancel" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
The idea being to slip an actual activity name into the title, like in an NSLog string.
Unfortunately, this doesn't work. Compiler tells me Expected ":"
Is it possible to use a variable like this, and if so, how?
Thanks!
call this line
#"No instances of %#",self.thisSpec.activityOfInterest
in one NSString
NSString *alertstr=[NSString stringWithFormat:#"No instances of %#",self.thisSpec.activityOfInterest];
after that call your UIAlertView and then rearrange the word delegate:nil into delegate:self
if (aOiCount == 0)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertStr message:#"Please select an activity or Cancel" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
I don't think this is valid Objective C syntax:
initWithTitle:#"No instances of %#",self.thisSpec.activityOfInterest
You need to wrap it in an NSString, or a self-contained form.
Consider one of the many NSString methods, such as stringWithFormat or construct one in a different way. Either way, you should pass a complete string here.

UIActionSheet works fine in iOS6 but crashes in iOS7 -- data structures were at fault

EDIT: The error is with the data structures that are being used during PDF generation. I'll be able to debug it once I can get a copy of OSX that supports iOS7. Thanks for all the help everyone!
At work I have Mac dedicated to working on iOS 6 apps. So far it hasn't been possible to update to a newer version of OSX so my version of XCode can't be upgraded to support iOS7 naturally. So long story short I can't debug iOS7 apps, so I am not sure why the app is crashing.
I have a UIActionSheet. I used to be using one with those completion blocks but was trying to debug so I have stripped everything away to just the basic barebones and it still crashes when I click on the button.
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil ];
[actionSheet showFromBarButtonItem:sender animated:YES];
That's just sitting on the end of a PDF generation method.
Any ideas? I've been researching this all afternoon and I haven't found any reason why it would stop working like this. I did try storing the action sheet as data in the view controller so the reference was being kept, but to no avail.
I am using ARC.
EDIT: I tried an UIAlertView with the same results. Maybe it's the PDF context ruining things somehow?
Thanks for all the help everyone.
EDIT: Big breakthrough in solving this one: When commenting out my PDF generation code that's before my action sheet/modal dialog/alert view, it opens without complaint. So it's some kind of hybrid issue, and I'll post the majority of my method here so everybody can see what's up:
-(void)shareTapped:(id)sender
{
if (actionSheet.isVisible)
return;
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"No mail setup" message:#"You must setup your email in the main settings app before you can share." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString *filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:#"ipc"];
[[PPCalculation sharedInstance] openCalculation:path];
}
[[PPCalculation sharedInstance] calculate];
// let's generate the PDF here!
NSMutableData* pdfData = [[NSMutableData alloc] init];
UIGraphicsBeginPDFContextToData( pdfData, CGRectZero, nil );
UIGraphicsBeginPDFPage();
// 200 lines of drawing commands here
UIGraphicsEndPDFContext();
// save to file
NSString* path;
for( NSIndexPath *indexPath in self.tableView.indexPathsForSelectedRows )
{
// should only get run once due to UI
Calculation* calc = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSString* filename = [calc.name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
path = [[[[self applicationDocumentsDirectory] path] stringByAppendingPathComponent:filename] stringByAppendingPathExtension:#"pdf"];
[[NSFileManager defaultManager] createFileAtPath:path
contents:pdfData
attributes:nil];
}
// ActionSheet, modal dialog, composer dialog, alert view, all of them crash when I try to put them here
UIActionSheet* sheet = [[UIActionSheet alloc] initWithTitle:#"Share" delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send By Email", nil];
[sheet showFromBarButtonItem:sender animated:YES];
}
Thanks again guys.
EDIT: It seems that, from my investigation and commenting things out line by line and sending them to the device over TestFlight that it's the internal data structures somehow not working properly, which is strange, as the rest of the app works fine. I probably will get a copy of Mountain Lion or something so I can debug this thing properly.
Try below code... May be it will help you...
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil];
//actionSheet.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
actionSheet.tag = ((UIButton*)sender).tag;
[actionSheet showFromRect:[(UIButton*)sender frame] inView:[(UIButton*)sender superview] animated:YES];
By sheer trial and error and commenting out code, I have narrowed it down to the PDF generation itself. Somewhere in the guts of the C++ data structures something is happening that is making iOS7 sad but the others fine. I've managed to convince the boss to order Mountain Lion so once that arrives I can build for iOS7 directly and debug it properly.
Try This it will help yo
your barbutton action method :
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:nil: delegate:nil cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Send by Email", #"Send To...", #"Open In...", nil ];
[actionSheet showInView:self.view];

how do you localize the contents of an UIAlertview

Using Base Internationalization, It's become really easy to produce automatic localizations based on Object ID. Here's a french version of something.
/* Class = "IBUILabel"; text = "Clear Memory"; ObjectID = "fHm-5n-KrF"; */
"fHm-5n-KrF.text" = "Effacer la mémoire";
But that only extends to things that Xcode can find in the storyboard.
It should be possible to include text strings in an AlertView. Surely.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Wheel Cicumference" message:#"Ground Trace (mm):" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
alert.tag = 10;
[alert addButtonWithTitle:#"Accept"];
[alert show];
Apple docs are vast, and I haven't found anything meaningful so far. I don't necessarily wan't the answer laid out in full for me, Just set me off in the general direction
The only way i know to localize the UIAlert is the following:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", #"Error")
message:NSLocalizedString(message, message) delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"OK") otherButtonTitles:nil];

If Statement Advice Needed

I’m trying to show an alert when a value greater than 200 is entered in my UITextField, rcdAtIan.text. I’ve tried this:
Self.rcdAtIan.text = self.circuit.rcdAtIan;
if (_rcdAtIan.text > #"200");{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Value Exceeded" message:#"Message here............." delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
and then this:
Self.rcdAtIan.text = self.circuit.rcdAtIan;
if (self.circuit.rcdAtIan > #"200");{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Value Exceeded" message:#"Message here.........." delegate:nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
}
but the alert is being shown when the view is loaded, rather than by my if statement. I know what I’m trying to say — if (_rcdAtIan.text => 200 "show my alert"); — but I’m unsure of the correct syntax.
You're trying to perform an arithmetic comparison on 2 string values. What you need to do is ask:
if ([_rcdAtIan.text intValue] > 200) {...
You can't compare strings like this (well, you can, but it doesn't make sense, since it performs a numerical comparison of the pointers which represent the strings, and it does not compare the contents of the strings). So, you may want to convert the strings to numerical values:
if ([self.circuit.rcdAtIan intValue] >= 200) {
// "200" or more has been entered
}

Showing an alert with Cocoa

I have been using VB.NET for a while and I switched to Xcode 4.
In the VB.NET environment, I used to type the following command in a button:
if TextBox1.text="" then
MessageBox.Show("You can't leave the textbox empty!, "Error!")
else
Label1.text = TextBox1.text
That is just an example. In Xcode, I want to do the same thing except for I want to have a Pop-Up Alert (in the iPhone) instead of the MessageBox in VB.NET.
Any Ideas?
Here you go
if ([TextBox1.text isEqualToString:#""]){
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"You can't leave the textbox empty!"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
} else {
Label1.text = TextBox1.text;
}

Resources