Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I have a method in my app that checks to see if some things are true.
- (BOOL)isToggleTurnedOn {
return ([self checkToggleStatus] != [self checkOtherToggle]);
}
When this method returns true, I display a modal.
if ([Preferences isToggleTurnedOn] == true) {
NSArray *welcomeTexts = #[
...
some data
...
];
WelcomeController *welcomeController = [[WelcomeController alloc] initWithText:welcomeTexts];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:whatsNewController];
navController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navController animated:YES completion:nil];
}
Now, this code is not as beautiful as it could by, in my opinion. I'd rather add the presentation of the controller as a parameter of isToggleTurnedOn. What's the best way to refactor this?
- (BOOL)isToggleTurnedOn {
return [self checkToggleStatus] != [self checkOtherToggle]
}
Drives me crazy to see code like this. Be more succinct:
- (BOOL)isToggleTurnedOn {
return ([self checkToggleStatus] != [self checkOtherToggle]);
}
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
In my application i want that user should be able to select multiple images from his gallery, but using UIImagePickerController we can select only 1 image at a time.
And as i am a fresher and don't have much knowledge of objective-c i am not able to implement Multi image picker components available on GitHub like- MAImagePicker, QBImagePicker, ELCImagePickerController.
If anyone has used any of these components kindly provide me with sample code and steps to implement that.
use ELCImagePicker
https://github.com/B-Sides/ELCImagePickerController
download from github and import in your project.
add select image button
- (IBAction)selectImg:(id)sender
{
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 100; //Set the maximum number of images to select to 100
elcPicker.returnsOriginalImage = YES; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.returnsImage = YES; //Return UIimage if YES. If NO, only return asset location information
elcPicker.onOrder = YES; //For multiple image selection, display and return order of selected images
elcPicker.mediaTypes = #[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie]; //Supports image and movie types
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}
get images from this methods.
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
for (NSDictionary *dict in info)
{
if ([dict objectForKey:UIImagePickerControllerMediaType] == ALAssetTypePhoto)
{
if ([dict objectForKey:UIImagePickerControllerOriginalImage])
{
UIImage* image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[arrImgs addObject:image];
}
}
}
}
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have on Unbutton and i want to open detail page on hard press on it.
so how it possible let me know.
#pragma mark - Previewing delegate
- (UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
UIViewController *detailVC = [self.storyboard instantiateViewControllerWithIdentifier:#"detail"];
detailVC.preferredContentSize = CGSizeMake(0.0, 568.0);
previewingContext.sourceRect = self.btnDetail.frame;
return detailVC;
}
- (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{
[self showViewController:viewControllerToCommit sender:self];
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to create a button that, when pressed, will open the Add Contacts Page of Phone Application. And once the Done/Cancel button is pressed, it should come back to my Application. I know this is possible, but i don't know how.
I think the Apple address book programming guide will help you:
ABNewPersonViewController *view = [[ABNewPersonViewController alloc] init];
view.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [[UINavigationController alloc]
initWithRootViewController:view];
[self presentModalViewController:newNavigationController
animated:YES];
ABNewPersonViewController is deprecated with iOS9. One should use CNContactViewController instead. Unfortunately there is a bug, refer to this thread (CNContactViewController Bug).
CNContactStore().requestAccessForEntityType(.Contacts) {ok, err in
guard ok else {return} // only if access is granted
dispatch_async(dispatch_get_main_queue()) {
let con = CNMutableContact()
let unkvc = CNContactViewController(forUnknownContact: con)
unkvc.contactStore = CNContactStore()
unkvc.delegate = self
unkvc.allowsActions = false
self.presentViewController(unkvc, animated: true, completion: nil)
}
and the delegate methods:
func contactViewController(vc: CNContactViewController, didCompleteWithContact con: CNContact?)
func contactViewController(vc: CNContactViewController, shouldPerformDefaultActionForContactProperty prop: CNContactProperty) -> Bool
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I found a repository on gifthub that is exactly what i was looking for. Can you help me how to code this to work with a single button. I don't enough experience yet with ios programmin to do this. I almost finished building my first app, but i need help with this.
Thanks in advance
https://github.com/BobDG/BDGShare
For a beginner I suggest this..
Its much easier. Just a few lines of code.
- (IBAction)shareButtonPressed:(id)sender {
NSLog(#"shareButton pressed");
NSString *texttoshare = #"text to share";
UIImage *imagetoshare = [UIImage imageNamed:#"beck.png"];
NSArray *activityItems = #[texttoshare, imagetoshare];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityVC.excludedActivityTypes = #[UIActivityTypeAssignToContact, UIActivityTypePrint, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
}
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
In an iOS view controller I typically have code like:
- (void)viewDidLoad
{
UIScrollView *scrollView = [[UIScrollView alloc] init];
// [several lines of code to configure the view]
[self.view addSubview:scrollView]
}
This tends to get cluttered so I add a helper method (e.g. createScrollView) to alloc, init, and configure the view. Is this an established pattern for building views and is there a convention for naming the helper methods? One thing I noticed is that the name initScrollView is not allowed because of ARC.
Here's the pattern I follow:
In init / initWithFrame: create your objects, and set any properties which will never change during the life of this controller:
- (instancetype) init {
self = [super init];
if (self) {
_textField = [UITextField new];
_textField.keyboardType = UIKeyboardTypeEmailAddress;
}
return self;
}
If you want to separate these out into methods like createTextFields, etc., that's fine, although it's easier to debug if you can see a list of everything instantiated in one place.
In viewDidLoad, set up the view hierarchy:
- (void) viewDidLoad {
[self.view addSubview:self.textField];
}
In viewWillLayoutSubviews, set the frames (if you're not using auto-layout):
- (void) viewWillLayoutSubviews {
self.textField.frame = CGRectMake(10, 44, 320, 50);
}
This approach will set you up for success handling view resizing and rotation events.