I have a tableview of items and when i click one row, I use uiactionsheet with 3 button: edit, remove and cancel. When I click button edit, I will open a modal view, so how can I do this ? what is the code to delete tablerow ?
If you want to delete a row from a UITableView, use the method named deleteRowsAtIndexPaths:withRowAnimation:. You can find all the details on the UITableView Class Reference page.
Also don't forget to remove the corresponding item from your model!
UIActionSheet has a delegate property. Add the UIActionSheetDelegate protocol to your view controller and set yourself as the delegate to the action sheet before you display it.
The action sheet will call
– actionSheet:clickedButtonAtIndex:
on it's delegate when the user selects and action.
In your implementation of this, you can do what you want, such as delete the row as fguchelaar described.
This method doesn't directly know which row the action sheet was called for, so you can either subclass UIActionSheet so it can store the indexPath, store the indexPath in your viewController, or pass the information in some other way.
Related
I have a table view with one custom cell that I have already built and hooked up. When the user taps the add cell button I want it to add a different custom cell. I don't know where to start this process. Do I build it on the storyboard then hide it? Or what is the best means?
You should create all of your custom cells in the storyboard, and then implement UITableViewDataSource methods, where you return whatever cells you want.
Check out the documentation
I have a Table View Cell and have added an action to it that I want to execute when a value is changed.
I have added the action method in the viewController
#IBAction func valueEntered(sender: NSTextFieldCell)
{
print("valueEntered")
}
I can edit the Table View Cell by double clicking on it, but my method is never called.
I know I have done this before but I must be missing a step.
You have to hook up the NSTableView delegate.
In your case, control-click and drag from Reseller Table up to File's Owner and choose delegate.
I have a table view controller and when you select a row an action sheet appears. Then the user would select an option, followed by -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex been called. But by that point I don't know which table view cell was selected to bring up the action sheet in the first place. Is there a way to pass an index path through an action sheet?
As UIActionsheet is child of UITableView you can use tag property to store the indexPath.Row.
I am assuming that your table has only one section. But if your table has more than one section then you can either make 2 class level variable to preserve the indexPath.row and indexPath.column OR you can customize UIActionSheet and assign respective value to properties of your action sheet class.
customizing action sheet will help you even when your tableViewDelegate and action sheet delegate are different.
Please post if you need help in writing code.
Save the index path while displaying action sheet and then click on clickedButtonAtIndex of your action sheet
[yourTableView selectRowAtIndexPath:savedIndexPath animated:YES scrollPosition:UITableViewScrollPositionBottom];
which will select your row.
Here savedIndexPath is your last selection of your table view
I want to be able to add 1 cell to the top of a UITableView after the user clicks on a button. How can I achieve this?
Update:
I also want to hide the cell if the user clicks another button
You can either call UITableView's insertRowsAtIndexPaths:withRowAnimation: to animate the insertion. Otherwise, you can just update your datasource without calling this method.
In order to do this you have to use the Navigation Controller, this is because once the user clicks the button your are suppose to send the user to a new view that edits and adds the new cell to the UITableView.
I have a UIViewController, and within that view i have UITableView added in IB
The UITableView displays the items from my array beautifully
I would like to be able to edit the items i.e delete them
BUT The UITableView does not have a navigation bar, and i am not using a navigation controller within this app i am just adding and removing views manually.
What i would like to do is place an "edit" button somewhere else within the view ... is this possible? and how might i go about this?
Put a button somewhere. In an action connected to it set TableView's editing property to YES - it should work fine. You also need to implement delegate's editingStyleForRowAtIndexPath method (return UITableViewCellEditingStyleDelete to allow to delete cells).
You could make one special cell (e.g. 1st row, 1st group) a button by implementing a adaequate didSelectRowAtIndexPath.
Or you could put buttons for editing/deleting in each cell (if single deletion/editing makes sense).
Or you could place the UIIableView on a super view wich also contains the button(s) as sub views.