UIactivityindicator doesn´t work in my project - uiactivityindicatorview

I´m trying to deal with activityIndicator in my iPhone app.
But it doesn´t work at all.
Inside my project I have a UISearchbar.
When people put the keyword and click the search result will show string in UIWEbview.
I really want the activity indicator show and animate while waiting for data and Stop when data is loaded.
Here is some of the code I use :
#implementation myFirstappController
#synthesize myWebview, activityIndicator;
- (void)webViewDidStartLoad:(UIWebView *)myWebview
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityIndicator startAnimating];
}
- (void)webViewDidFinishLoad:(UIWebView *)myWebview
{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityIndicator stopAnimating];
}
///Here is code inside the UISearchbar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSString *keywords = searchBar.text;
NSString *infos = [NSString stringWithFormat: #"%#", keywords];
NSString *rs=nil;
if ([infos isEqualToString:#"Iloveyou"]){
rs =#"<span style='color:#3B5998; font-size:25px;font-weight: bold;'>I love you too </span> <span style='color:#666; font-size:18px;'> -rte,-rt </span> ;
[myWebview loadHTMLString:rs baseURL:nil];
}
- (void)dealloc {
[myWebview release]; //<-------JUST FILL THIS LINE**********************
[activityIndicator release];
[searchBar release];
[super dealloc];
}
#end

In your example you're "loading" a string, which will be instantaneous, so (because the iPhone combines animations) the indicator will never animate.
You should try your code with a remote URL.

Related

Focus Ring in field editor for NSTextFieldCell in an NSTableView

I have a cell-based NSTableView with a text cell in a particular column. I want to provide a custom field editor so that I can do auto completion without the user pressing F5.
#implementation AutoCompleteFieldEditorTextView
-(id)init
{
self = [super init];
if (self)
{
self.focusRingType = NSFocusRingTypeDefault;
self.fieldEditor = YES;
}
return self;
}
#end
This works ok except the focus ring does not exist. Even if I add:
-(void)drawFocusRingMask
{
NSRectFill([self bounds]);
}
-(NSRect)focusRingMaskBounds
{
return [self bounds];
}
it still does not work. How can I get the exact focus ring that appears with the default NSTextView used as a field editor in an NSTableView?
Have same problem and for solving I'm using next approach. This method overloaded in custom NSTextFieldCell which creates and return your custom NSTextView:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
[super drawInteriorWithFrame:cellFrame inView:controlView];
if([controlView.window firstResponder] == self.maskTextField)
{
[super drawFocusRingMaskWithFrame:cellFrame
inView:controlView];
}
}
Hope this help someone in future.

UIDocumentInterationController item option menu will not dismiss when click in the Navigation bar

Title: UIDocumentInteractionController dismissing the popup when clicking anywhere in the navigation bar.
My code works find. It works well in my iPhone and iPad simulator for the most part. It does what I want., however, my issue is dismissing the default popup menu. It goes away if I click in the view area, it goes away if I pick an option in the popup, and it also goes away if I click in the tab bar area. This is good. However if I click anywhere in the navigation bar it stays put. And if I click any of the items in the navigation bar it crashes. I would like the default popup to dismiss if I click in the navigation bar as well.
outputURLViewController.h
#import <UIKit/UIKit.h>
#interface outputURLViewController : UIViewController<UIDocumentInteractionControllerDelegate,UIPopoverControllerDelegate>
{
IBOutlet UIWebView *previewWebView;
}
#property (nonatomic, strong) NSString *outputURLString;
#property (nonatomic, strong) NSString *outputURLName;
#property (nonatomic, retain) UIWebView *previewWebView;
#property (nonatomic, strong) UIDocumentInteractionController *docController;
- (IBAction)actionButton:(id)sender;
#end
outputURLViewController.m
#import "outputURLViewController.h"
#interface outputURLViewController ()
{
NSArray *myButtonArray;
UIBarButtonItem *myActionButton;
}
#end
#implementation outputURLViewController
#synthesize outputURLString;
#synthesize outputURLName;
#synthesize previewWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Creates my action put and put it in the right side of navigation bar
myActionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(actionButton:)];
myButtonArray =[[NSArray alloc] initWithObjects:myActionButton, nil];
self.navigationItem.rightBarButtonItems = myButtonArray;
NSURL *url = [[NSBundle mainBundle] URLForResource:outputURLString withExtension:#"pdf" subdirectory:#""];
//displays my document in the webview
[previewWebView loadRequest:[NSURLRequest requestWithURL:url]];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
//action that display my options in a default popup menu
- (IBAction)actionButton:(id)sender
{
NSURL *url = [[NSBundle mainBundle] URLForResource:outputURLString withExtension:#"pdf" subdirectory:#""];
if (url) {
self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[self.docController presentOptionsMenuFromBarButtonItem:myActionButton animated:NO];
}
}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller willBeginSendingToApplication:(NSString *)application{}
- (void)documentInteractionController:(UIDocumentInteractionController *)controller didEndSendingToApplication:(NSString *)application{}
//dismiss my popup menu in the view, but not the navigation bar when click
- (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller{}
#end
As you can see it very simple default popup menu code. It does what I want. I just trying to figure how to prevent it from crashing when a navigation item button is click before the popup is dismissed.
My Error that I get is:
Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'
My DocumentInteractionControllerDidDismissOptionsMenu: does work when I click in the view or any where else except the navigation bar. So is there away to prevent anyone from clicking another button in the navigation bar until the uidocumentinteractioncontroller is dismissed or have it dismiss when they tap in the navigation bar area? Or is this a normal bug that doesn't have a fix?
Decide to hide the navigation items when the popup is active.
I used this code in the myActionButton section
if ( IDIOM == IPAD ) {
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.hidesBackButton = YES;
}
and this code in my documentInteractionControllerDidDismissOptionsMenu
if ( IDIOM == IPAD ) {
self.navigationItem.rightBarButtonItem = myActionButton;
self.navigationItem.hidesBackButton = NO;
}

how to create a camera overlay view that recognized swipe gestures?

I am trying to create a camera overlay that can recognize swipe gestures to push to other views.
I am wondering if I can still use the UIImagePicker or if I have to use the AVCaptureSessionManager.
Also i would prefer to create the overlay view in the story board is there a way to do that?
can I select a view inside the storyboard controller be the camera overlay and simply present the UIImagePicker on view did load?
I've never used the Storyboard to create a camera overlay, but I have created a xib which works fine. You can create the overlay viewController in the normal (xib) way, complete with gesture recognizers, then you can handle them directly in that VC or use a delegate (most likely the VC which presented the camera).
Some code -
-(void)setupCamera
{
self.picker = [[UIImagePickerController alloc] init];
_picker.sourceType = UIImagePickerControllerSourceTypeCamera;
_picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.overlay = [[OverlayViewController alloc] init];
_overlay.delegate = self;
_picker.cameraOverlayView = _overlay.view;
_picker.delegate = self;
[self presentViewController:self.picker animated:YES completion:nil];
}
The overlay -
-(id)init
{
self = [super initWithNibName:#"OverlayViewController" bundle:nil];
if (self)
{
// set up stuff
}
return self;
}
... & some code which handles the swipe -
-(IBAction)swipe:(UISwipeGestureRecognizer *)sender
{
// swipe stuff
[self.delegate doSwipeStuff]; // if you want the delegate to handle it
}
Hope this helps.

Using ImagePickerController to get photo from library ok but navigating away then back to same view the image is gone

I am trying to build a view where a user can select an image and it is retained within that view after navigating away from the view and coming back again. As a simple test app, I have created two view controllers. The first view controller has a forward button and uses a modal segue to go to the second view controller. The second view controller has a back button (modal segue back to first view controller) a Choose button and a Image button. So far I have configured the choose button to use the imagepickercontroller to select an image from the library and display onto the button which works no problem. The issue is that when i press the back button and the forward again back to the same screen the image isn't retained i have to reselect it. The intention is for the user to be able to take a picture or video of themselves performing an action and then select it within this app and have the picture displayed there for future reference.
My coding is as follows:
ViewController.h
#interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
IBOutlet UIButton *selectFromPhotoLibraryButton;
IBOutlet UIButton *displayPictureButton;
}
#property (nonatomic, retain) UIButton *selectFromPhotoLibraryButton;
#property (nonatomic, retain) UIButton *displayPictureButton;
- (IBAction)selectPicture;
#end
ViewController.m
#implementation ViewController
#synthesize selectFromPhotoLibraryButton;
#synthesize displayPictureButton;
-(IBAction)selectPicture
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info
{
UIImage *image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
[displayPictureButton setImage:image forState:UIControlStateNormal];
[self dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
Please let me know if you require any of the other bits of code (its only the default app stuff, no further modification).
As looking to your problem
I think you have to store selected image in NSUserDefault as archived data or something like that.
When u come back to second view then check first in NSUserDefault for image is saved or not.
If u got it then assign it to UIImage object by unarchiving.
As I have not implemented it so can't be sure.
I've just set something like this up myself, I have the chosen image immediately placed in a UIImageView.
First, set up your view controller as a UIImagePickerDelegate:
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
Then wherever you want to init the UIImagePicker, alloc, init and set its delegate to self:
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
[self presentViewController:imagePicker animated:YES completion:nil];
And then I have the image picker storing the UIImage into the ImageView and also into the NSUserDefaults.
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {
UIImage *image = [[info objectForKey:UIImagePickerControllerOriginalImage] retain];
[userDefaults setObject:image forKey:#"image"];
[userDefaults synchronize];
[self dismissViewControllerAnimated:YES completion:^{
[self updatePreviewImage:image];
}];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *) picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
I hope this works for you, and anyone else that view this post.

Buttons not working in IOS5

i built an app on ios 4.3 and it worked fine but when i run it on the new ios the back buttons dont work. Heres my code to go to the next xib:
-(IBAction)Selection3Page:(id)sender;{
//show next view
Selection3Page * nvc = [[Selection3Page alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:nvc animated:NO];
[nvc release];
}
and this is the code to return back to the first xib:
-(IBAction)done:(id)sender{
[self.parentViewController dismissModalViewControllerAnimated:NO];
}
please help!!
The API for dismissing modal views was changed somewhat in iOS 5. Try this instead:
if ([self respondsToSelector:#selector(dismissViewControllerAnimated:completion:)])
{
NSLog(#"didTouchDoneButton 5.x");
[self dismissViewControllerAnimated:YES completion:nil];
}
else
{
NSLog(#"didTouchDoneButton 4.x");
[self dismissModalViewControllerAnimated:YES];
}
post some NSLogs in there somewhere and check if the methods are actually getting called... I would start around that..

Resources