UITableView: delete section controls - iphone

Is there a way to add delete controls, like in UITableViewCell, on a table section? I see two ways:
Use table cell instead of sections.
Write own UIView section class, which will show delete controls.
Regarding the first way - as I think, it could be an easiest way in my situation.
The second way may be better from the implementation point of view, but it will take more time.
May be I missed another way? Any suggestions?

The only way I see is to provide your UITableViewController Delegate or Subclass with the method called:
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
This gives you the power to display any kind of UIView as a section-header. within this view you can place controls that enable the user to delete sections.
I hope this helps a bit.

Related

TableView scrolls to bottom and perform some action

In my application there is a table view.What I want to do is when I scrolls the table view and when it come to its end row I want to perform some action.
Please tell me which approach should I use to do this.
Thanks in advance!!
I think you should make a check in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)
when it loads the last row then call that method.
I think this will work. because table does not load all data at once but i loads data when user scroll
I think (don't the docs up here) but there is no method within the UIScrollViewDelegate that handles the scrolling to the bottom. There is when scrolling to top, but can't remember if there is scrolling to bottom. Check it please.
If not, the easy way is just to check the indexpath.row at cellForRow. If it is your last row, call whatever action you want.

Question about iPad/iPhone controls

On the iPhone/iPad in the general settings they have a list of itms that display a '>' at the right hand side. When pressed it slides to another view.
Is this a control from the object palette? If so, which control? If not, what is the best way to achieve similar functionality.
I have looked at a lot of the samples on the Apple Dev site, but I cannot find a control like that, or at least I don't remember seeing it.
Any help on this foolish question is appreciated!! -:)
Thanks
Any time you see a view that is a scrollable list of items, you are looking at a UITableView, and each item in the list is defined using a UITableViewCell. To make the UITableViewCell show the '>', you simply have to set its 'accessoryType' to 'UITableViewCellAccessoryTypeDisclosureIndicator'.
This only draws the '>', it doesn't slide in the other view. However, when a user selects a UITableViewCell, it will call a function on its delegate:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
In here, you will write the logic that slides in the new view controller (using UINavigationController's -pushViewController:animated:).
To learn more about how to use UITableView, I would highly suggest reading through the UITableView programming guide. It also links to downloadable projects with sample code.
You probably mean the combination of a UITableViewController and a UINavigationController. Create a new "navigation based app" to check out how it works & have fun. :)
Both are available in IB under the Controllers section.
The control you're looking for is a UITableview with disclosure indicators. To get the disclosure indicators (either the grey chevrons or the blue buttons), set editingAccessoryType for each tableview cell. That will give you a '>' on the right side of each item in your tableview.
When you tap on one of the '>'s, the tableview's delegate will have this method called:
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
This is different from the method that is called if you tap anywhere else on the row:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
As dominostars said, you create another view and use UIViewController's pushViewController method to have another view slide in from the right.

Custom UITableViewCell dilemma

I got a kind of problem. At this point I have made a custom tableviewcell, nothing fancy just two labels with 1px white shadow beneath the text. The problem is that when the user (me) select a cell the blue highlighting looks really awkward because of the shadow. So I need to disable/remove the shadow on highlighting.
I have not found any methods which are being called once the user selects the row, just after the user removes his finger.
So at this point I need to subclass UITableViewCell just to write two lines of code in the setSelected-method that does it. Are there any better ways to do this? And yes, I just add views to the contentView property of the cell.
And what is the layoutSubviews-method for? I don't find it in documentation but obviously it is in the iOS so...When does it get called and in what context?
Because when I subclass a UITableViewCell, what should I do with the sizes of the view-components?
Thanks in advance!
The below method is called just before the user is about to select the row....
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

How to place two buttons on top of tableview

i have been looking, but can't find my answer.
my question is how to make a tableview with two buttons above it.
here is a pic of something i would like to do.
I have the grouped tableview, but can't figure out how to make it look like the image.
thanks for the help
http://img137.imageshack.us/i/imagezjb.png/
Create a view with your two buttons as subviews, then set the tableHeaderView property on your table view to be that view.
#LucasTizma's answer is valid but you can also return views for header sections by implementing the method below, which returns a UIView. In this case, you will be able to return different views for different header sections so if for instance you had a header for Games and a header for Utilities on the same tableView, you could return different images/buttons for each header (i.e. a special game promo in the game section and a different one for Utilities).
Basically the process is the same: you create a UIView, add the buttons/images as subviews and then return it on the method.
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Cheers,
Rog

Decrease UITableViewCell width and put custom button on the left

Is there any way to decrease the standard width of grouped UITableViewCell and put a custom button on the left side(outside of cell boundary)? I tried to change the cell size but it keeps same
You are going to have to fake the editing mode.
What I mean by that is that as AtomRiot said you have to subclass UITableViewCell so that when in editing mode you show the button you want on the left, outside the cell.
But first things first.
To change the indentation level for your cells all you need to do is implement this delegate method for the UITableView
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
So that takes care of it. Then in your UITableViewCell subclass all I would do is to implement the method
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
which I assume is called when the table the cell belongs to has changed to editing mode.
There I would fade in (or animate in any way you want) a button to appear on the left of your cell.
I have done it inside a grouped-style cell but never on the outside.
Give it a try!
You could subclass UITableCell and add your own custom views inside of it. I have not personally added a button inside one but it should work. It may get confused with the row selected call the tableview makes if you are implementing that.
The Cocoanetics blog seems to have a pretty good solution to this:
http://www.cocoanetics.com/2010/03/how-to-shrink-cells/