In my app I am using a button to print a tableview of information to a printer. I am using the simple code below to print. I get output fine and even in duplex mode. I use the exact output table for a variety of reports. My problem - How do I include a title and the column headers?
(IBAction)btnPrintTable:(id)sender {
NSPrintOperation *op;
op = [NSPrintOperation printOperationWithView:rptTable];
if (op)
[op runOperation];
else{
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:#"Cancel"];
[alert setMessageText:#"No Table Data available for printing"];
[alert setInformativeText:#"Cancel and create table data"];
[alert setAlertStyle:NSWarningAlertStyle];
if ([alert runModal] == NSAlertFirstButtonReturn){}
}
}
There are 6 column headers: Number: Extension: Year: Type: Price: Description:
I have read 'About MAC Printing' and 'Printing Programming Topics for Cocoa'. I can not reference a table header/column design detail. I can not find anything in pagination topics referencing this issue. Can anyone help?
Related
I have an app that worked great before Apple insisted users be given a choice between "Always" and "When In Use" for Location Manager.
The app used iBeacons to send invitations to play games and accept.
When "Always" is selected the beacons work fine but when I switch to "When In Use" they don't work at all.
I started out using "Always" but change the following code to give users the choice.
In the app's plist I added "Privacy-Location Always and When In Use Usage Descriptions and Privacy-Location When In Use Usage Description" and removed the "Privacy-Location Always Usage Description".
In the app's Delegate I have this
- (void)locationManager:(CLLocationManager *)manager
didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedAlways){
NSLog(#"Always");
AlertView2 = [[UIAlertView alloc] initWithTitle:#"Dual player on two devices is enabled."
message:#"To save battery power go to Settings/Privacy/Location Services and choose \"Never\" when not using I'M GAME. Two people can still play on one device when in \"Never\" mode. To recieve invitations to play only when the app is open select \"When In Use\"."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:#"YES" forKey:#"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
NSLog(#"WhenInUse");
AlertView2 = [[UIAlertView alloc] initWithTitle:#"Dual player on two devices is enabled."
message:#"To save battery power go to Settings/Privacy/Location Services and choose \"Never\" when not using I'M GAME. Two people can still play on one device when in \"Never\" mode. To recieve invitations to play while app is in background select \"Always\"."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:#"YES" forKey:#"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusRestricted){
NSLog(#"restricted");
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusDenied){
NSLog(#"denied");
AlertView2 = [[UIAlertView alloc] initWithTitle:#"Dual player on a single device Only."
message:#"To play on two devices go to Settings Privacy/Location Services and choose \"Always\" or \"When In Use\" for I'M GAME. In \"Always\" you can recieve invites while app is in background, in \"When In Use\" invites only appear when the app is on screen. To preserve battery choose \"Never\" when not using I'M GAME."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[AlertView2 show];
[[NSUserDefaults standardUserDefaults] setObject:#"YES" forKey:#"accessKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
NSLog(#"undetermined2");
[locationManager requestAlwaysAuthorization];
[locationManager requestWhenInUseAuthorization];
}
}
Does iBeacon need to have Privacy-Location set to "Always" to work?
So I just found out that in "When In Use" you can't monitor for beacon region is entered or exited only find its range. So I guess the question is how would I use range to send a notification to my user.
When you have your app authorized to do beacon ranging only when it is in the foreground, it's easy to simulate entry/exit logic with just a didRangeBeacons callback.
Set up one class variable:
var beaconLastSeen: Date? = nil
Add this code to your didRangeBeacons method:
if beacons.count > 0 {
if beaconLastSeen == nil {
// call didEnterRegion logic here
}
beaconLastSeen = Date()
}
else {
if beconLastSeen != nil && Date() - beaconLastSeen > 30 {
beaconLastSeen = nil
// call didExitRegion logic here
}
}
You will get an exit event 30 secs after the last beacon detection. You will get an enter event when one is first seen.
EDIT: Here's the same code in Objective C:
NSDate *beaconLastSeen = nil;
...
if (beacons.count > 0) {
if (beaconLastSeen == nil) {
// call didEnterRegion logic here
}
beaconLastSeen = [[NSDate alloc] init];
}
else {
if (beaconLastSeen != nil && [[[NSDate alloc] init] timeIntervalSinceDate: beaconLastSeen] > 30 ) {
beaconLastSeen = nil;
// call didExitRegion logic here
}
}
I'm trying to create a text box with multiple fields, but I'm having trouble getting the second to show (as a matter of fact, when I type the second field in, it causes my text box not to show up all together.)
Here's what I have:
-(IBAction)popupCheckIn {
//UIAlertView *alertCheckIn = [[UIAlertView alloc] initWithTitle:#"Check in" message:#"Please fill out the following to check in." delegate:self cancelButtonTitle:#"Check in." otherButtonTitles:#"Cancel.", nil];
//[alertCheckIn show];
UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:#"Check in" message:#"Please fill out the following fields to check in." delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * nameField = [alert textFieldAtIndex:0];
nameField.keyboardType = UIKeyboardTypeDefault;
nameField.placeholder = #"Your Name";
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
UITextField * hostField = [alert textFieldAtIndex:1];
hostField.keyboardType = UIKeyboardTypeDefault;
hostField.placeholder = #"Host Name";
[alert addButtonWithTitle:#"Check in."];
[alert show];
When I run this code, I get an error that says "Thread 1: signal SIGABRT" and my pop up won't come up at all; when I have just the name field, it works fine.
What am I doing wrong with my second text field? Thanks!
I think that your error arises because that type of UIAlertView doesn't contain more than one UITextField, and when trying to access the second it raises a NSRangeException. This is according to the docs.
https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/instm/UIAlertView/textFieldAtIndex:
I tried your code, the entire error message is:
2014-06-26 17:13:56.213 Testing1[2444:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textFieldIndex (1) is outside of the bounds of the array of text fields'
The issue, is that you only have ONE UITextField with the UIAlertViewStyle set to UIAlertViewStylePlainTextInput. So this part of code ([alert textFieldAtIndex:1] is causing the crash).
Repeating the line alert.alertViewStyle = UIAlertViewStylePlainTextInput; won't create a new one.
The only way to get 2 UITextFields, is to use the UIAlertViewStyleLoginAndPasswordInput UIAlertViewStyle.
A way could be then to set the second one (like the first one) is like this:
[hostField setSecureTextEntry:FALSE];
But personally, I think that I don't recommend it. It may be blocked in the future.
Since we cannot custom really the existing UIAlertView since iOS7 (can't add subview), I'd suggest you create (or find in CocoaControls/GitHub) your own CustomAlertView-like.
You'll want to use alert with the alert style UIAlertViewStyleLoginAndPasswordInput. See this answer: UIAlertView with Two TextFields and Two Buttons
I've recently found out, that I do not receive any EKCalendar objects from EKEventStore in iOS7. In iOS 6.x.x there are no problems with same code snippet. When I'm trying to access defaultCalendarForNewEvents - I do receive a single EKCalendar object (as expected).
I do request access to entity type EKEntityTypeEvent.
The snippet:
__block NSMutableArray *calendarsArray = nil;
if ([self.eventsStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
[self.eventsStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
if (status == EKAuthorizationStatusAuthorized) {
calendarsArray = [[NSMutableArray alloc] initWithArray:[self.eventsStore calendarsForEntityType:EKEntityMaskEvent]];
}
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!" message:#"You haven't granted access to calendars. Expected things are not going to happen." delegate:nil cancelButtonTitle:#"I understand" otherButtonTitles:nil];
[alert show];
}
}];
} else {
calendarsArray = [NSMutableArray arrayWithArray:[self.eventsStore calendarsForEntityType:EKEntityTypeEvent]];
}
I do receive 0 objects into calendarsArray. I've also tried to get it by "running through" all EKSources that are of type Local or CalDAV ([source calendarsForEntityType:] - got the same empty (0 object containing) set).
By the way - access to calendars IS granted.
Any suggestions?
After a brief investigation I have found out, that the problem was not in the code. It appears that the problem is in iOS 7.0.3 itself.
After deleting all the sync'ed calendars from the iDevice and adding it back all of the calendars were displayed both within the native Calendar application, and the one I made. After taking this action my code was able to retrieve the calendars from EventStore not depending on the method I would access calendars (via EKSources or EKEventStore itself).
I'm using ShareKit 2 on an iOS app for version 5 or later. I've got the app configured to use Facebook correctly, and when the action sheet is activated, that's the only option that appears. I want to use the built-in Twitter sharing system, but the option doesn't come up in the action sheet. Here's my code:
SURL *url = [NSURL URLWithString:launchUrl];
SHKItem *item = [SHKItem URL:url title:#"Title" contentType:SHKShareTypeURL];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
[SHK setRootViewController:self.view.window.rootViewController];
[actionSheet showInView:self.view.window.rootViewController.view];
As per the instructions. I've got a custom DefaultSHKConfigurator class, in which I suppose these are the relevant methods:
- (NSString*)sharersPlistName {
return #"MySHKSharers.plist";
}
- (NSArray*)defaultFavoriteURLSharers {
return [NSArray arrayWithObjects:#"SHKTwitter",#"SHKFacebook", #"SHKMail", #"SHKTextMessage", nil];
}
Again, only Facebook comes up as an option. For completeness, here's my "MySHKSharers.plist" file (the relevant part):
<dict>
<key>actions</key>
<array>
<string>SHKMail</string>
<string>SHKTextMessage</string>
</array>
<key>services</key>
<array>
<string>SHKTwitter</string>
<string>SHKFacebook</string>
</array>
</dict>
So any ideas why I can't get Twitter, Mail and TextMessage to show up in the action sheet?
If you want to configure the sharers shown in the actionsheet I found this post helpful:https://gist.github.com/1181552
I ran into trouble getting actions (email, text message, etc) to show in the default actionsheet. My solution was to create a custom actionsheet and then to call Sharekit like this:
- (IBAction) getSharingSheet:(id)sender{
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:#"Share"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Facebook", #"Twitter", #"Save to Photo Library", #"Email", nil];
[sheet showInView:self.view];
}
and then my didDismissWithButtonIndex:
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
switch(buttonIndex)
{
case 0:
SHKItem *item = //some item
[SHKFacebook shareItem:item];
break;
case 1:
SHKItem *item = //some item
[SHKTwitter shareItem:item];
break;
case 2:
SHKItem *item = //some item
[SHKPhotoAlbum shareItem:item];
break;
case 3:
SHKItem *item = //some item
[SHKMail shareItem:item];
break;
default:
break;
}
}
Hope this helps!
I had this same issue and just solved it. This may or may not be the same issue that you are facing.
After poking around a bit to see how the action sheet was being built, I found that in SHK.m it was pulling stored favourites out of NSUserDefaults.
+ (NSArray *)favoriteSharersForType:(SHKShareType)type
{
NSArray *favoriteSharers = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:#"%#%i", SHKCONFIG(favsPrefixKey), type]];
....
}
These stored results are preferred even over what you've defined as the "default" favourite sharing services. Clearing out these favourites solves the issue.
I have an Facebook app on http://developer.facebook.com of type "Native iOS" which is connected to the actual iOS app using the new Facebook iOS SDK 3.0.
How can I know if the multiple people that already install the the app and authorize the Facebook app too so I can put them in some list, but this not my question because I know that there is a field called "installed" that return true when the user install the app.
So if I want to filter the returned friend by the FBFriendPickerViewController based on if the user use the app, so how I can use the installed field or something else to filter the friends.
Note: I know where to filter the friend (*) all I need is the field or the property that I need to check to make sure the user is install my app.
*- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker
shouldIncludeUser:(id<FBGraphUser>)user
I found a way to do this :
I create a method that send an FQL to those I need (for example my friends that they are male)
and then compare those returned by this request with the already exists by the FBFriendPickerViewController using the method :
- (BOOL)friendPickerViewController:(FBFriendPickerViewController *)friendPicker shouldIncludeUser:(id<FBGraphUser>)user
for the request :
NSDictionary *queryParam = [NSDictionary dictionaryWithObjectsAndKeys:#"query", #"q", nil];
[FBRequestConnection startWithGraphPath:#"/fql" parameters:queryParam HTTPMethod:#"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (error)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops" message:#"Some thing go wrong !, Try again" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
else
{
NSArray *friendInfo = (NSArray *) [result objectForKey:#"data"];
for(int i = 0; i < [friendInfo count]; i++)
{
[self.friendsNames addObject:[[friendInfo objectAtIndex:i] objectForKey:#"name"]];
}
}
}];
As you see I have an NSArray that store the filtered friend, the next step is to compare them in the delegate method above.
Hope you find it useful.