I would like to implement an animation when a user tries to delete and reorder a cell. Now it is coming instantly when I click on the edit button. Can you help me to make this code as an iphone contact app animation.
-(IBAction)edit:(id)sender
{
tabView.editing = !tabView.editing;
}
Take a look at UITableView class reference and you should be able to find the instance method you need.
The instance method setEditing:animated: will be able to do what you want. The second parameter will give the animation transition if you set it to YES.
For example:
[tabView setEditing:!tabView.editing animated:YES];
Related
I normally post source code and examples of UI but I think its more related to an iOS7 change and I cant see it being a code bug (yet). I would have to post so much code and UI that it would be counter productive. So here is my best non-visual description:
Since upgrading a project to iOS7 I am finding that if I put call to change a UILabel or calling setText of a UIButton in a ViewDidAppear or ViewWillAppear it puts the new text right on top of the old text.
Since developing for iOS I have never had to do anything different. If I do this:
lblMyHours.text = #"12";
It shouldnt just throw that on top of my existing label.
This especially happens inside of a UITableView where I have created an iVar for a UILabel thats in a UITableViewCell. If a user makes an adjustment to a value after clicking on a cell (it takes them to a detail screen to edit), when I pop back I have it recalculate in ViewDidAppear. In that recalculating I am resetting a label like the above. But it doesnt clear out the old.
You might be adding a new label every time you return a new cell.
You should just replace the text of the current label instead.
There are two way to achieve this, one you are already doing and as #Guilherme rightly pointed out. The other way is to create a custom tableview cell and put the UILabel property in there. As for the viewDidAppear scenario, you can create a uilabel in ther .h file (in the #interface declaration) and then initialize it in ViewDidLoad method and simple use in ViewDidAppear method without having to declare it again.
I would suggest that you follow the way I described for ViewDidAppear issue, and for the UITableView issue, search for UILabels in subview of the cell everytime cellForRowAtIndex method is called and remove it from the subview, something like this before adding a new label
for(UIView *view in cell.subviews)
{
if([view isKindOfClass:[UILabel class]])
{
[view removeFromSuperview];
}
}
Hope this helps.
i have asked this question Changing UIView To be instance from UIControl Programmatically 24 minutes ago but i he didn't benefit me , so i typing this question in another form hoping that you can help me
i have a view that its class is from UIControl (so of course it will receive events)
and i have a button that i want it to change my view to normal UIView instance (so of course it will receive events)
so how to make that
i want the code if changing the view to UIView here
-(IBAction)pauseButton:(id)sender
{
//here
}
i want the code of changing the view to UIControl here
-(IBAction)playButton:(id)sender
{
}
Firstly make sure you have an IBOUTLET for that view or object and make sure it is connected.
For example we will say the view is called the_view
Now you can over uncheck the UserInteractionEnabled checkbox within the interface builders property tab of that object or type a line of code. The second option is better if you want the button to raise the event of stopping touches being allowed.
For the first option I have uploaded a video showing the basic steps:
Click Here For tutorial
For the second on option you can use this code:
the_view.userInteractionEnabled = NO;
Or if you are trying to hide your default view simply use:
self.view.userInteractionEnabled = NO;
or as noted in the answer above:
[self setUserInteractionEnabled:NO]
You can not change an object's class in objective-c. If you just want the control to stop receiving touches, you can use:
[self setUserInteractionEnabled:NO]
Anyone has ever come into the problem that UITableView need long press to trigger the didSelectRowAtIndexPath method?
If you have used any gesture recognizer try to removing it and check if it causing the problem or not ?
Other wise
Not sure but The problem might be in the UITableView has delaysContentTouches turned ON. Turn this OFF so touches get through to the cells faster.
In my situation I had a UITapGestureRecognizer on my view for hiding my keyboard.
This solved the problem:
tap.cancelsTouchesInView = false
I had exactly the same trouble :
I used the Tap Gesture recognizer to manage different action in my View Controller
I wanted a classic tap (short click) to trigger the didSelectRowAtIndexPath method but just a long press working by default
My solution to select a cell in Table View by a short tap (press) :
Select your Tap Gesture recognizer in your Story Board
Go to the attributes inspector and deselect "Canceled in view"
You have to add UILongPressGesture to your cell's view and on fire just call didSelectRowAtIndexPath (better will be to call another method - not standard UITableViewDelegate's method) from your class that adopts UITableViewDelegate.
I will suggest You create own protocol, inherited from UITableViewDelegate, add there method for long press behavior method and enjoy. Something similar to:
#protocol LongPressTableViewCellDelegate <UITableViewDelegate>
- (void)tableView:(UITableView *)tableView didLongTapCell:(UITableViewCell *)cell;
#end
Your delegate in this case would adopt not standard UITableViewDelegate, but this one. Also You have to create own cell (inherited from UITableViewCell) and add there delegate property (id ) that will be used when long press fired.
Also there can be situation that standard didSelectRowAtIndexPath will be fired before your long press will fire, so I suggest you to disable standard selection behavior for table view:
_tableView.allowsSelection = NO;
This has probably been asked before but I'm new to iOS Development and when I found confused me. I have a tableView and want to allow the user to tap a button that says "Edit" and they can delete items. I also want the edit button to become a "Done" button, which will stop edit mode. (The user can add data into the tableView from another option, which I will probably need to research how to do.) I don't have a storyboard as I built the app in an app called Interface. Everything is all in code.
The UIViewController class provides a method that gives you the standard Edit/Done button. You can do something like:
self.navigationItem.rightBarButtonItem = [self editButtonItem];
This standard button is setup to call the setEditing:animated: method. When used with a UITableViewController, the table view is automatically toggled between regular and edit mode along with the view controller.
There are plenty of specific table view delegate and data source methods you need to implement on top of this to facilitate actual table editing but using this standard button at least easily lets you toggle in and out of editing mode.
You will need to add the UITableViewDelegate methods.
I presume the 'Done'/'Edit' Button is the same in some place such as your UINavigationBar?
You will have to manually change the title for the button.
Remember to set your ViewController as the delegate for tableview too.
This delegate method informs that you wish to have the table eidtable.
– tableView:editingStyleForRowAtIndexPath:
This method tells you you will start editing:
– tableView:willBeginEditingRowAtIndexPath:
(hint: change button title here)
Likewise this tells you editing is done:
– tableView:didEndEditingRowAtIndexPath:
(hint: change button title here)
In the XCode IDE, at the bottom of the view controller in the MainStoryboard editor, are two boxes: First Responder, and Exit.
I know what a firstResponder is programatically within the code, but in the storyboard editor, I can't seem to do anything useful by it.
Am I able to use the first responder in this area to somehow set the first responder of the view? I'd like the first textfield to be active on load and I have tried right+click and dragging to no avail. I know I can set it programatically in the viewDidLoad method, but is there some way of doing it here?
And what is the green Exit for?
There are no good answer for this question, so I am posting my answer:
From here:
Note: You probably won’t be using the First Responder very much. This is a proxy object that refers to whatever object has first responder status at any given time. It was also present in your nibs and you probably never had a need to use it then either. As an example, you can hook up the Touch Up Inside event from a button to First Responder’s cut: selector. If at some point a text field has input focus then you can press that button to make the text field, which is now the first responder, cut its text to the pasteboard.
Edit:
1) First Responder is very useful if you are using text fields with keyboard notifications. I use it to make keyboard disappear, make an outlet to variable currentFirstResponder of your class, and in viewWillDisappear:
[self.currentFirstResponder resignFirstResponder];
2) You can read about unwind segues ("Exit" box) here
I've never used it and probably never will but you can assign an object to be the first in line to receive the events from the UI.
I suppose you could be creating a UIView subclass and add it in to a UIViewController but you actually want some other object to receive and process the events other than the UIViewController you are adding it to.
I found this link which kind of explains it a bit better.
First Responder: The First Responder icon stands for the object that the user is currently interacting with. When a user works with an iOS application, multiple objects could potentially respond to the various gestures or keystrokes that the user creates. The first responder is the object currently in control and interacting with the user. A text field that the user is typing into, for example, would be the first responder until the user moves to another field or control.
Exit: The Exit icon serves a very specific purpose that will come into play only in multiscene applications. When you are creating an app that moves the user between a series of screens, the Exit icon provides a visual means of jumping back to a previous screen. If you have built five scenes that link from one to another and you want to quickly return to the first scene from the fifth, you’ll link from the fifth scene to the first scene’s Exit icon.
More here
You don't see this very often, where a deleted answer is actually correct, and the comment (likely influencing its deletion) on it is totally wrong! I'll try and improve on it.
Usually the IBAction you want to hook up to a button is in the view controller containing the button. However if the IBAction is in a different controller, e.g. a parent controller then drag from the button to the First Responder object and you are able to select the IBAction in the parent controller!
As the hidden answer states, how this is implemented is the action is sent to nil, which has the effect of the responder chain (i.e. view hierarchy) being searched for the action, as follows:
[UIApplication.sharedApplication sendAction:#selector(nextObject:) to:nil from:self forEvent:nil];
An example is a custom UITableViewCell. Add a UIButton to the cell but you want the action to go up to a View Controller that has an embed segue to a UITableViewController. Drag the touch up instead action to the First Responder and select the action in the container view controller. In the action to find the indexPath simply loop the visibleCells and check if the sender is isDescendantOfView:
- (IBAction)cellButtonTapped:(id)sender{
for(UITableViewCell *cell in self.tableViewController.tableView.visibleCells){
if([sender isDescendantOfView:cell]){
NSIndexPath *indexPath = [self.tableViewController.tableView indexPathForCell:cell];
NSLog(#"tapped %#", indexPath);
}
}
}
Another example could be a reload button: say your first view controller shows an downloaded item with an IBAction to reload it to get the latest data, then your child controller shows some detail, but you also want them to be able to reload the main item from within the detail, just add a button in the detail and drag its action to First Responder and select the reload IBAction in the parent controller. This allows you to hook up buttons to parent actions with no additional code like delegate methods!
For this to work the action needs to be in the responder chain hierarchy or it won't be found, you can read how the chain is built up in the docs. Also note if called from code the view needs to have appeared, viewWillAppear is too soon.