UIButton has to be tapped repeatedly before touchUpInside fires - ios4

I have two UIButtons (start and dismiss), contained by a UIView, contained by an outer UIView.
There is nothing special about the buttons.
This is all done in a xib file.
For one of the buttons, it just works.
For the other, when the code is running (simulator or on the iPad doesn't matter), a touchUpInside message is sent to the corresponding controller only on about 10% of taps. tap-tap-taptaptap-tap...tap-tapFIRE. Sometimes tapping slowly and methodically works better. Sometimes.
When it does finally fire, the message (dismissWindow:) is called/received/processed correctly.
The button has a referencing IBOutlet ("dismiss", although I've tried it both with and without one).
The button, the view and the parent view are all "User interaction enabled" and not hidden.
I've tried with the button both on the parent view, and on the subview.
I've tried with the action set to the view container, and to First Responder.
I've ensured that the button is in front.
Is there some urban legend about dodgy and/or finicky UIButtons on the iPhone/iPad? Am I missing some setting someplace?
The other button on the view, Buttons in other xib files, or those created dynamically work as expected. It is simply this one xib file and this one button.
.h
UIButton *dismiss;
...
#property (nonatomic,retain) IBOutlet UIButton *dismiss;
.m
#synthesize ..., dismiss, ...;
...
-(IBAction)dismissWindow:(id)sender {
[[controller detailViewController] dismissWaitView:self];
[self removeFromSuperview];
}
So I throw this out to the collective consciousness. What can I try?
TIA,
rip

In the end, what I noticed was that the UIButton was of type "custom" and the text was "Done" and the style was "Done". Changing any one of those was sufficient to make the button work as I expected it to.
I changed the text from "Done" to "Finished", and it suddenly started working.

Related

iOS how to display new UIView?

New to iOS dev. Kindly correct me if i am wrong?
I have a UIWindow, and rootviewcontroller is :
#interface ViewController : UIViewController
{
IBOutlet UIButton *but;
}
#property (nonatomic, strong) UIButton *but;
-(IBAction) butButtonPressed;
#end
ie: If i make this Viewcontroller as a root view controller, the UIView that is available in the ViewController is displayed. Understood.
I have created a new class inherited from UIViewController, and along with its .xib file.
So xib file name is : view1.xib,
My Objective is to display this view when the button is pressed.
Now i have created a button and button press invokes butButtonPressed. Inside of butButtonPressed, i did the following.
myViewController *vcontroler = [[ViewController alloc] initWithNibName:#"view1" bundle:nil];
[self.view.window addSubview:vcontroler.view];
Application crashes. What am i doing wrong ? Kindly point out.
This...
[self.view.window addSubview:vcontroler.view];
...is a really bad strategy (and I seriously wish I knew where people are finding it as a way of showing views). If you create a view controller, you should use it rather than just treating it as a temporary container that you can rip views out of.
If you want vcontroler to look like a child of your first controller (and you have a UINavigationController), use pushViewController:animated:. Otherwise you can show it as modal with presentModalViewController:animated:.
If you only want to add a view to the existing display, put the view in ViewController's hierarchy and show/hide it.
If you absolutely must have it as a sub-controller of ViewController then you need to keep a reference to it and manage its lifecycle inside the owning controller.

Core Data can't save anything

I have started learning Core Data programming and I have a problem. The book that helped me in my studies is written for XCode3, and I'm using XCode4. I surfed on the Net and found this article . I've done everything just like it's written there and created my entity just like it's written in the book. To enable the save action I was told to CTRL+drag the Save menu item to the AppDelegate in my nib. I did so, but when I make changes in the program and then save it when I reopen it it seems that nothing has saved. How could I solve this?
Thanks in advance.
You need to connect save button with an action handler. It must have this structure:
.h file
#interface YourClass : UITableViewController
//... ivars, properties
-(IBAction)saveButtonPressed:(id)sender;
#end
.m file
-(void)saveButtonPressed:(id)sender {
[self.managedObjectContext save:nil];
}
Now the ctrl-dragging should work. Drag from the button to the controller. In the resulting black popup you should be able to select saveButtonPressed.
Edit
An even better method is to do this: open the split view controller. On the left you have your storyboard / IB with button, on the right the .h file of your view controller class. Now control drag from the button to a space above #end in the .h file. In the popup, select "Action" (not "Outlet"), name it e.g. saveButtonPressed. Press OK and Xcode will generate automatically all of the above. Now just fill in the save instruction in your new button handler.

UITextField: can't type text but smilies, copy/paste, and backspace is fine

I think this is strange, I have made my own class that inherits from UIAlertView. In this class I add a UITableView as subview and the cells contains a UILabel and a UITextField.
the class implements: UITableViewDelegate, UITableViewDataSource and UITextFieldDelegate,
In the cellForRowAtIndexPath each cell.uiTxtField.delegate is set to self.
The following happens both in the simulator and on the real iPhone device:
When I set the pointer/finger in the UITextField the keyboard pops up and
textFieldDidBeginEditing is triggered, that's fine and as expected.
When I leave the UITextField, textFieldDidEndEditing is triggered,
that's also fine and as expected.
But when I start to type text, the cursor stops blinking but no text
is typed to the UITextField.
I can copy and paste text by holding down the pointer/finger in a UITextField that contains text, select copy and then paste it in another UITextField (or the same).
The backspace works fine.
It also let's me type in symbols and smilies etc.
The only thing I can't type in is characters/letters and numbers
The return button doesn't trigger textFieldShouldReturn
Since textFieldDidBeginEditing and textFieldDidEndEditing is triggered I assume my delegate setup is fine, but I can't understand why I can't type text and why textFieldShouldReturn is not triggered.
This might be related.
Any help is appreciated.
have you put this in the "init" method of your custom class?
try putting a code like this in your implementation file...
#implementation CustomAlertClass <UITextFieldDelegate>
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//
self.YourTextField.delegate = self;
}
return self;
}
#end
Short answer: Make sure you don't have any code that messes with the 'editing' property on UITextField.
I had the same symptoms where I was definitely setting the delegate properly and textFieldDidBeginEditing and textFieldDidEndEditing were getting called, but textFieldShouldReturn and shouldChangeCharactersInRange were not getting called. I also could not type any characters, but I could copy paste into the text field. In my case I also happened to be putting the text fields inside cells in a UITableView. My situation was slightly different in that the delete button did not work.
Where I went wrong, was that I was not using a raw UITextField in my cells, I had my own subclass of UITextField. My subclass had a property 'isEditing', which I was modifying in the UITextFieldDelegate methods and used to figure out how to scroll the table view when the text field was selected. This was overriding the 'isEditing' method on UITextField with is used as the getter for the UITextField 'editing ' property. Once I got rid of my subclass isEditing property everything behaved as expected.

Uimenucontroller controller not responding to touch

I have a uimenucontroller that I am using on a uiwebview. The menu controller works fine on simple text websites however on larger websites i.e. http://www.foodnetwork.com/recipes/giada-de-laurentiis/grilled-chicken-with-basil-dressing-recipe/index.html my custom menu item will not respond to touches. When tapped it highlights blue briefly then back to black, the menu is still displayed and myAction is nevere called. Sometimes if I click rapidly othe menu controller it will respond so I believe it may be something to do with the responder chain and or the size of the web page. I initialize the menu controller as follows:
// in view did appear:
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:#"Item1" action:#selector(myAction)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:item1]];
-(void)myAction
{
//do something
}
Thank you! I have been stumped by this for 2 weeks and am out of ideas...

BackButtonBarItem not working properly in iphone

I implemented the following code to show the navigation bar with a backbuttonbaritem.
[mapNavigationItem setTitle:#"Tracking"];
[mapNavigationItem setRightBarButtonItem:nil];
[mapNavigationItem setLeftBarButtonItem:nil];
UIBarButtonItem *stopTrackingBarButton = [[UIBarButtonItem alloc] initWithTitle:#"Stop Tracking" style:UIBarButtonItemStylePlain target:nil action:#selector(stopTracking)];
[mapNavigationItem setBackBarButtonItem:stopTrackingBarButton];
[mapNavigationBar pushNavigationItem:mapNavigationItem animated:NO];
[stopTrackingBarButton release];
The stopTracking button is displayed on the screen, but no title is displayed. When i click on the stopTracking button, it disappears and then shows the title.
Could someone please tell me whats happening??
Ok i think i wasnt clear enough,
I have a mapview with buttons in the tab bar, when the app starts the navigation bar shows 2 buttons, when i click on one of the Tab bar items, it should clear the navigation bar buttons and add a back button bar button item only. I am successful upto this stage.
But when i click on the BackBar button item, it disappears, and does not perform the action assigned to it.
FYI:
IBOutlet UINavigationBar *mapNavigationBar;
IBOutlet UINavigationItem *mapNavigationItem;
If you want to use a different title for your back button than the previous navigation title, then you need to change it just before pushing the new view controller and change it back again after popping it.
So something like:
self.navigationItem.title = #"Stop Tracking";
[self.navigationController pushViewController:mapNavigationItem animated:NO];
and in this class's viewWillAppear
self.navigationItem.title = #"Tracking";
Edit:
If you are not using the backbarbutton for taking the navigation controller back then dont set it as a backBarButton simply set it as left barButton item.
Plus it also seems like you are using same navigation bar for both tabs. not a good idea. Load both tab views from different viewcontrollers and add two different navigation bars to those views.

Resources