UITableView add new custom cell onto selected cell or another suggestion - iphone

I'm really confused about that;
I have an example view. it contains an UITableview, this tableview contains approximately four or five rows. I don't know am i right or wrong way ? I'm trying that when the user click to the cell the table, i'm trying to add new custom cell onto the clicked cell with animation, this custom cell contains some action and information about the clicked cell. This is actually like to FaceBook start page on the iphone. In Facebook program when the user click to plus icon on the left side of row on start page view, it's working but how.
Can someone provide me an example code or any suggestions ?
Thank you very much.
EDIT :
Guys let me add more detail with some screenshots.
alt text http://img24.imageshack.us/img24/8159/img0398.png
As you can see on this picture, displaying list of data or some think like that.
When the user press the talk balloon (with plus icon) on the right side or per row.
alt text http://img682.imageshack.us/img682/1726/img0399.png
Custom cell or view (whatever) is coming from leftside to onto the selected cell,
with transition.
I think, my question was very clear now.
How can i do that ?

To show plus button in the cell you must set table view's editing property to YES and implement delegate's editingStyleForRowAtIndexPath method - return UITableViewCellEditingStyleInsert for the cell you need.
To add the new cell (with animation) to the table view you must implement
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
in your datasource - make necessary changes in your data source (the number of rows in table must be increased by one after this method) and call
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation for your tableview to animate changes.

Related

iOS: cancel delete event UITAbleViewDelegate

I want to know the delegate method that gets called when the user cancel the delete operation of the UITableViewCell. Now to answer the potential question that "Why do I need this?", following is the scenario:
I have a table view where the item is displayed (which is left aligned to the main view) in a UILabel and its price is displayed in a separate UILabel (which is right aligned to the main view).
Now once the user presses the red (kind of no entry) button to delete any item, the whole cell is indented to the left and half of the price is clipped because of being out of the view. This looks quite ugly and hence I hide the price label upon press of this 'pre-delete' button (which works fine). But I want to display the price tag back when the user dismiss the delete button without deleting the cell. but I am unable to find the cancelDelete kind of event for tableview cell.
Thanx :-)
Here's something that might work instead, it stops the tableview from indenting the cells while editing:
Set UITableView's shouldIndentWhileEditing property to NO.
Implement the delegate-method tableView:editingStyleForRowAtIndexPath: method:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Or you can do this when you create your cells:
cell.shouldIndentWhileEditing = NO;
Hopefully this works for you.

How to reload and animate specific cell in UITableView in iPhone sdk

In my application, I am using tableview with some rows. In each row I am displaying some part
of text.In that row below text there is a Expandbtn. If we click that we will display the whole
text.
For that I want to use reloadRowsAtIndexPaths: WithAnimation: method . I want to apply this
method when I click Expandbtn in each cell.
I am using that above method for expanding text in cell. My Problem If I expand text in first
and go to 2nd cell it appears to be expanding and it is overlaping with first cell.
If I scroll the table to the top, then first cell appears to be NOT Expanding.
Can Anyone Help me in this.
Thanks in Advance.
Relating to "If I scroll the table to the top, then first cell appears to be NOT Expanding." It sounds like you are not dynamically determining the height of the rows.
Are you implementing the delegate method - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath in your NSTableViewController? If so, make sure you are returning a different value before and after you expand the row.

Woes with the selected button state in custom UITableViewCells

I have a custom UITableViewCell with two buttons in it, mycell.m/mycell.h/mycell.xib. In the XIB I have given the buttons a sample label, and I change that text in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *).
Now, when I click the buttons, while I'm holding my finger on it, it will show the sample text instead of the actual text. And should I miss the button and touch inside the custom UITableViewCell, both buttons change text to the sample text, and they don't redisplay the text I set in cellForRowAtIndexPath until I scroll the cell off-screen and back again.
Any clues to what I might be doing wrong? I haven't found any way to set a selected text.
Cheers
Nik
Well, trying again...
I set up a mini project and recreated the problem. After puzzling over why the text I set wasn't being used, I finally realized that you can set a different title for every control state (setTitle:forState:). Normally, if you just set titleLabel.text, then you're setting it for UIControlStateNormal, which is then used by default for all other states. However, IB apparently sets the sample title you specify for all the states separately, not just for normal state. So in your code, you're indirectly doing a setTitle:forState:UIControlStateNormal, but the titles set by IB for all the other states are remaining unchanged. So when you hold down the button (UIControlStateSelect) or you hit the cell (UIControlStateHighlight), then the sample label is displayed. SO...either remove the sample label in IBuilder (the easy path), OR set the label for all the relevant states.
Old incorrect answer:
cellForRowAtIndexPath is only called when the tableView needs to display a cell (e.g. when scrolling back onto the screen.) It's not called anytime a cell is on the screen. Sounds like you've got another routine (e.g. buttonPressed) that's set up as an IBAction from the buttons.

Appearance of table cells when deleting

I'm trying to make a table view with an appearance much like the default Weather application provided by Apple. However I'm struggling a bit to make the table cells look correctly.
I would like all the cells, except the first one to be deletable. The problem is that the default cells have the small delete button on the left side of the cell instead of inside the cell. This causes the cells to shrink to the right, except the first one which keeps its size since it's not deletable.
So my question is if there is any way to tweak the default UITableViewCell to have the same behavior as the cell used in the Weather app? Or do I have to implement my own cell with button animation, etc, etc?
It turned out that somebody else had already answered this in a slightly different question:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
it looks like that all apple is doing is making the background black for the delete button content area. i would try doing something like that first.

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/