UIButton stopped responding during development - iphone

I have a couple of buttons in a view. These were tested a few days ago and were working fine. Today for some reason they stopped working. The buttons are custom, with an image. They are connected to an action like:
- (IBAction)walkTurnByTurn:(id)sender {
NSLog(#"Clicked Turn By Turn Walk");
CLLocationCoordinate2D destination = self.loadOficina.coordinate;
MKPlacemark *endLocation = [[MKPlacemark alloc] initWithCoordinate:destination addressDictionary:nil];
MKMapItem *endingItem = [[MKMapItem alloc] initWithPlacemark:endLocation];
[endingItem setName:self.loadOficina.title];
NSMutableDictionary *launchOptions = [[NSMutableDictionary alloc] init];
[launchOptions setObject:MKLaunchOptionsDirectionsModeWalking forKey:MKLaunchOptionsDirectionsModeKey];
[endingItem openInMapsWithLaunchOptions:launchOptions];
}
I deleted the button and created it again, connected it to the action. It is enabled, user interaction enabled as well. It looks like it is just not responding to touches at all because it doesn't change color when clicked.
Any ideas what might have happened?

It's probably out of the bounds of its superview. If the superview frame is 0,0,100,100 you can add the button as a subview that starts at, say, 200,200. It will show up on the screen but it won't respond to events. This is happening to a lot of people with iPhone 5 layouts. They accidentally hardcode the window to 320x480. The controls show up at y positions > 480 but they aren't interactive.

Related

Set accessibility badge on a tabbarItem

I have a tabbar application. If there is a badge on a certain tab VoiceOver pronounces N items. I'd like to make it pronounce N messages.
How do I do that?
I had a similar problem,
it seems that UITabBarViewController.tabbar is handling accessibility differently than other views.
So my solution was placing another uiview above the badge as a subview of [tabbar superview] and adding accessibility to this view:
At viewDidLoad:
self.badgeAccessibilityView = [[UIView alloc] init];
//use tabBarView.frame to calculate
self.badgeAccessibilityView.frame = frameAccordingToBadgeLocation;
self.badgeAccessibilityView.userInteractionEnabled = YES;
self.badgeAccessibilityView.isAccessibilityElement = YES;
[self.tabBarView.superview addSubview:self.badgeAccessibilityView];
On badge value change:
self.badgeAccessibilityView.accessibilityLabel =
[NSString stringWithFormat:#"%d Notifications", badgeValue];

IOS Application Freezes

My application is freezing with a reason that I could not figure out, it does not crash but it freezes.
basically what I did was having another view inside my view that is hidden at first place, after when I click a button this view will be appeared and it includes a UItextfield and a UIPickerView. the pickerview data is updating while I edt the UItextfield and I select one of the values from picker view then basically press addButton, when I add thi whole view will be hidden again and the selected value of the pickerview will be added another UITextfield in the main view.
when I do this first time it works fine. it sets the value of the UI textfield which is on the main view to the correct value. but when I try to change it, get that view unhidden and select another value in the pcikerview and press on addButton again the application freezes. No crash appears.
I want to inform you about this the value of the UITextfield on the main view is changing I checked it on the logs. and the method that do the clicking action completely works. But it freezes.
I couldnt figure it out, I need some help :)
EDIT:
I figure out that the UITextField on the main view cause this freeze, when I set the text
[myTextfield setText:#"somethng"];
the UI freeze. when I comment this out it works pretty fine. But It works fine at first time. does not work on the second time.
Any help will be appreciated.
EDIT 2 (I added some code):
-(IBAction)addButtonClicked:(id)sender
{
leftBarButton = [[UIBarButtonItem alloc] initWithTitle:#"Done" style:UIBarButtonItemStylePlain target:self action:#selector(pickerViewDoneClicked:)];
[[self.navigationController.navigationBar.items objectAtIndex:0] setLeftBarButtonItem:leftBarButton];
[self.pickerContainer setHidden:NO];
}
-(IBAction)pickerViewDoneClicked:(id)sender
{
[[self.navigationController.navigationBar.items objectAtIndex:0] setLeftBarButtonItem:nil];
NSLog(#"%#", self.myTextField);
NSLog(#"old val %#", self.myTextField.text);
// the text field on the main view.
[self.myTextField setText: selectedText];
NSLog(#"new val %#", self.myTextField.text);
[self.pickerContainer setHidden:YES];
}
//in picker view source
selectedText = [pickerData objectAtIndex:row];
As I told the first time I add it works fine I can see the value on the textfield
but when I do the same action again and click done the app freezes.
I checked the reference of the textfield before after and no reference missing
I can see the new value and old value as well. but the UI freezes.
Just to be sure: you do not perform any call to UIKit on non-main thread?
I was using this piece of code for padding for my text field,
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
self.myTextField.leftView = paddingView;
self.myTextField.leftViewMode = UITextFieldViewModeAlways;
I am not sure how it effects it but second time I change the text into the textfield I was getting my screen freezed.
Thanks again for any effort to help me.

How do you manage memory when adding a UIImageView to another windows view?

Since I think I scared everyone away with my other recent post ( Memory management when adding a UIImageView to another viewController's view from another viewController's view ) and I'm running out of time, I'd just like to ask this in simpler terms. If you want to know I'm doing with more detail, refer to the other post.
How do you manage memory, and releasing, when adding a UIImageView to another windows view?
i.e. I'm creating a UIImageView in one view, and adding it as a subview in another windows view. The other window is being used by a TV.
Right now I have:
mapImageViewEx = [[UIImageView alloc] init];
// I think you can ignore these two things below
CGPoint p = mapScrollView.contentOffset;
mapImageViewEx.frame = CGRectMake((p.x*-1), (p.y*-1), mapImageView.frame.size.width, mapImageView.frame.size.height);
NSString *mapExFileLocation = [[NSBundle mainBundle] pathForResource:[map_List objectAtIndex:mapNum] ofType:#"png"];
NSData *mapExIMGData = [NSData dataWithContentsOfFile:mapExFileLocation];
mapImageViewEx.image = [UIImage imageWithData:mapExIMGData];
// finds the other window's view controller's view
UIView *containerExViewP = (UIView*)[del.switchExVC.view viewWithTag:9000];
// adds it
[containerExViewP addSubview:mapImageViewEx];
Problem I'm having is that it keeps stacking up memory use every time I exit the view. Releasing the image in the iPad screen view's dealloc does nothing.
change
mapImageViewEx = [[UIImageView alloc] init];
to
mapImageViewEx = [[[UIImageView alloc] init] autorelease];
autorelease means that the reference count will be decremented at some unknown point in the future.
the addSubview will increment the count, so you don't have to worry about it.
As long as the parent view is properly disposed of, mapImageViewEx will be released.

Implementing my own navigation controller?

I have a tab bar app. Under one of the tabs i want a uisegmentedControl in the top navigation view, that controls what view is currently displayed. This is dead easy if i just exchange the view, but i want to do it in a more organized and generic way, by using one uiviewcontroller for each view and exchanging them in the most optimzed way.
i guess step one would be to know exactly what a tabbar controller sends to a navigation controller/view controller when a tab is changed, and work it out from there.
Can any one point me in the right direction?
Some time ago I stumbled upon SegmentsController which I found in this blog entry from red artisan.
I used it in conjunction with a UITabBarController, but without knowing I did it wrong. Not wrong as in "it crashs" or "it doesn't do what i want" but wrong in the sense that I have to forward each UIViewController call (like viewDidAppear, receivedMemoryWarning etc) to the child viewControllers. The app with the wrong code is still in the app store and I never received a complain about it.
But I played around a while and figured out how to use it right. It's a bit of a hassle but imho it's absolutely worth it.
I'll show you the correct version that I have right now, I'm creating the UITabBarController in Interface Builder so I have to change the tab in code. Which introduces another piece of mess, and maybe there is room for improvements. But right now I'm satisfied with this solution.
NSMutableArray *items = [self.tabBarController.viewControllers mutableCopy]; // tabs from tabbar configured in IB
// The two child vc that will appear in the segment control
SomeViewController_iPhone *tvcs = [[[SomeViewController_iPhone alloc] initWithNibName:#"SomeView_iPhone" bundle:nil] autorelease];
SomeOtherViewController_iPhone *tvct = [[[SomeOtherViewController_iPhone alloc] initWithNibName:#"SomeOtherView_iPhone" bundle:nil] autorelease];
NSArray *viewControllers1 = [NSArray arrayWithObjects:tvcs, tvct, nil];
// the nav controller acts as a wrapper around the child viewcontrollers
UINavigationController *navController1 = [[[UINavigationController alloc] init] autorelease];
navController1.tabBarItem.title = NSLocalizedString(#"FirstTab", nil);
navController1.tabBarItem.image = [UIImage imageNamed:#"tabImage1.png"];
navController1.navigationBar.tintColor = [UIColor navBarTintColor];
firstTabSegmentsController = [[SegmentsController alloc] initWithNavigationController:navController1 viewControllers:viewControllers1];
// uses a NSArray category that basically creates a NSArray that has the title properties of the vc in viewControllers1
firstTabSegmentedController = [[UISegmentedControl alloc] initWithItems:[viewControllers1 arrayByPerformingSelector:#selector(title)]];
firstTabSegmentedController.frame = CGRectMake(0, 0, 222, 30);
firstTabSegmentedController.segmentedControlStyle = UISegmentedControlStyleBar;
firstTabSegmentedController.selectedSegmentIndex = 0;
[firstTabSegmentsController indexDidChangeForSegmentedControl:firstTabSegmentedController];
[firstTabSegmentedController addTarget:firstTabSegmentsController action:#selector(indexDidChangeForSegmentedControl:) forControlEvents:UIControlEventValueChanged];
// replace first tab from interface builder with this
[items replaceObjectAtIndex:0 withObject:navController1];
as you see it needs a bit of setup, but in my opinion this solution is better than anything else I've tried throughout the time. I hope I de-NDAed the code correctly.
Edit: Uploaded a sample project: BeautifulColors.zip
Just exchanging the views and keeping up with the current view's viewController is the best way to implement a UISegmentedControl in this regard.
Note: by exchanging the views i mean adding a subview to the current view and removing the old one.
You might be interested in the method below, which is implemented by the UITabBarControllerDelegate
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController;

How can I disable re-taking of pictures?

I use the built-in camera of the Iphone in my apps dans I have two questions.
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.sourceType = UIImagePickerControllerSourceTypeCamera;
ipc.delegate = self;
ipc.allowsEditing = NO;
[self presentModalViewController:ipc animated:YES];
First, my camera let the user use the picture he took or Retake, I want to take off this option, the user must have only one chance to take his picture.
Second, I want a change the title of the Cancel button on the left, because my app is in french.
For the "Cancel" button, I think you may try with internalization and localization. I don't know exactly how to do.
If you want to control the camera flow, it is harder than the normal way. You have to replace the default control buttons (in the bottom of the camera screen) with your own control. There are 2 methods that you need to do:
First, you need to set showCameraControls to NO: picker.showCameraControls = NO
#property(nonatomic) BOOL showsCameraControls
Then you need to supply your own view: picker.cameraOverlayView = YOUR_OWN_VIEW
#property(nonatomic, retain) UIView *cameraOverlayView