I am creating an app tableview based.
On tableview i have 6 sections. Under those sections there are some rows.
Also i have UIButtons on each section.
Now when i click the UIButton on a particular section it will call an alert with textfield. When i type row name and press ok it will insert the row in that particular section. I have created alert with textfield. But when i try the rest it does not show up the row. What do i do??? I have been stuck in this for a couple of days.
Thanks in advance.
If you are inserting or removing any row or section in your tableView then you need to update your tableView's dataSource and then populate through it in cellForRowAtIndexPath: method by calling `[self.tableView reloadData].
Related
Background
I'm really struggling to work out how to handle editing mode of a UITableView and hide some rows in when editing commences.
I'm using a grouped table view style with multiple sections and multiple rows per section. The last row of each section is titled "Add new...".
The idea is to allow the end user to click the "Add new..." row within each section and then be taken to a new screen where they fill in some fields and then are returned to that tableview with their new row added within the relevant section. So the last row does not really relate to the datasource and is more of a UX thing.
I've managed to get the Add row appended to the end of each section.
The problem
I have a button that calls: tableView setEditing:animated: and this insets all the rows and adds a delete icon to the left of each row.
What I don't want to do is allow the user to delete the "Add new..." row. So my orignal thinking was to just remove the delete capability for those "Add new..." rows using the tableView:canEditRowAtIndexPath:.
This worked but looks really crap as all the rows are inset apart from the "Add new..." rows.
So my current thinking is when edit mode commences just remove the "Add" rows from the table view and then when editing mode finishes add them back again.
I tried to do this by traversing all the rows when the user clicked the edit button but it seems you can only get rows that are currently visible using cellForRowAtIndexPath:.
So I can remove the ones that are visible but as soon as the user scrolls down the tableview the add buttons are still there for the sections that were not visible (at the time editing was initialised).
Help!
Does anyone know how I can just hide the "Add" rows from each section when the user edits the table and then add them back after?
I'm looking for the same functionality that the contacts app uses when the user edits a contact.
Actually you did already close the answer, just use the method cellForRowAtIndexPath to pick up the cell you want to hide, and set its hidden property to YES. You make it!
Oh, I am sorry that I had not noticed you are using the group style, so my suggestion is that you can try to separate the add button to the others, like include it in a single section.
You can display a green (+) button on the "Add line" row so it lines up with the deletable rows.
Simply override -tableView:editingStyleForRowAtIndexPath: in your table view delegate and return UITableViewCellEditingStyleInsert for that row.
What about removing the Add line(s) from the actual data source and just calling [tableView reloadData] then when edit mode changes back, add them back into the data source and reloadData again.
return YES from canEditCellAtIndexPath for every cell in the section then in override
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {} and return UITableViewCellEditingStyleNone for the "add line" row else return UITableViewCellEditingStyleDelete
I want to add my customized tableviewcell in my tableview when user selects a cell I have some buttons on that customized cell and want to give user option as soon he selects a cell.
Any suggestions and guidance to move on from here?
you have to use customize cell when cell is created and change the image of the cell when it will selected.
Create two custom cells, one for the normal rows and other for the required row. When the user touches a particular cell, you can record it's indexPath and reload the tableView. When the cellForRowAtIndexPath is called the second time after tableView reload, you can identify the row with the flag set earlier. You can then create a new cell for it.
I have a grouped tableView with 5 sections and i want to add buttons per sections.
For example i have add (+) button in all sections near the section title.
Can i do that?
Regards,
ZaldzBugz
You can implement tableView:viewForHeaderInSection: method in table's delegate and create custom view for section header there with title and button (and with whatever else you need).
I am newbie to iphone programming. I doing an mail like app in that i have to show inbox information in table view and at the final of dragging i should need "show 20 more messages" button. is there possibility of showing that?
if please can you provide with me a codes.
Regards,
sathish
Sure, you just have to manage it manually:
Add one extra row to your table view.
In tableView:cellForRowAtIndexPath:, if the indexPath corresponds to the last possible row (which is the extra row you added), create a cell that represents the button.
In tableView:didSelectRowAtIndexPath:, if the indexPath corresponds to the last possible row, have your datasource load the additional data and send a insertRowsAtIndexPaths:withRowAnimation: to your table view.
I have a UITableView with some rows in it. Is it possible to show a UIPickerView when tapping on a row in the table?
I want the UIPickerView to change its data depending on which row it the UITableView that is selected.
If you set a delegate set for UITableView then that view will send you the appropriate delegate methods. From there you can reload your picker view. Click here to find out more.
edited: corrected link.