how to slide UILabel in uitableviewcell when swipe to delete is used - iphone

I have a custom uitableview with a UILabel to the right of the cell as shown below
I have enabled swipe to delete, but when the button appears the UILabel is covered, I am guessing this is because my custom tableviewcell has not been informed about the delete button..
I am wondering how I go about moving the UILabel to the left of the delete button when the swipe is detected.

This is how you would do it if you create the cell in a xib.
You create a view the same size as the cell and put all of your labels inside it. Create an outlet for this view. Then in the .m of the customCell you add the view to the contentView.
[[self contentView] addSubview:cellView];
Then, in the xib add struts so that the labels stick to the edge of whatever side they are nearest and you should be good to go!

Related

iPhone: How to add a UILabel on top of a UITableView?

In my Universal IOS4 app, I have a UITableview in my xib and I control it with my UITableViewController. As you know tableview by default covers all the area in window left from the navigation bar on top and the toolbar at the bottom.
What I want is to add another UIComponent(probably a big UILabel) just under the navigation bar and place the scrollable tableview just under that UILabel, so UIlabel is not scrollable but only the table is
How can I do and control that?
Thanks
Never mind: I think this will scroll with the table.
You can set the section header to the view below. This may work if you only have one section. Best solution would be to change to a UIViewController.
Programmatically add a header to the table
UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0,0,320,30)] autorelease];
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(0,0,50,30)] autorelease];
label.text = "Hello";
[view addSubview:label];
self.tableView.tableHeaderView = view;
I would suggest not to go with using UITableViewCOntroller at all. If you use UITableVIewCOntroller to ease the way you use Delegates and Data Sources, then you will have to face this kind of Customization problems.
You will have below problems if you UITableViewController:
can not set the background to a custom UIImage. You can only set the UITableView’s BG property. If you use a Custom VC and add a UITableView to it. you can entirely customize what to keep on top of the View, widtt and height of your table view.
You can not have a static Header view in your View at all. Because if you use UITableVC, you can only have the default header that you can create using Table View's data source methods. But if you use a customized VC and add a TableView to it, you can add your own customized header or controls as a header.
only advantage you will have if you use a UITableViewController is that if you have UITextFields in your Table View, UITableViewCOntroller will automatically scroll the hidden text field to above the Keypad if you start editing one.
I would not suggest you to add anything to UIWIndow, as only the first added view to window will get the rotation events
http://developer.apple.com/library/ios/#qa/qa1688/_index.html
One simple idea is to have another UIViewController (let's call this a_viewController) and set the tableview (let's call it a_tableView) and the label (samewise, a_label) as its subviews.
[a_viewController.view addSubview:a_tableView]
[a_viewController.view addSubview:a_label];
TableView header may not work in case you want the label to stay as you scroll.
But if you have only one section in your tableview, section header may become a handy option.
Can i make a table's tableHeaderView position fixed as I scroll?
One of the way is you can add on UIWindow. But make sure you handle it properly while navigating views... Following is the way...
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];
Create your UILabel instance (myView) and add it as subview in UIWindow...

Another Button at UITableView Editing Mode

I need an additional button next to the Delete button when in editing mode of UITableView Cells. Any suggestions for the purpose is appreciated. Thank You.
I would suggest you first subclass UITableViewCell. In the respective init method you create the button and add it to the contentView as a subview. Make the button hidden. After that you overwrite layoutSubviews and position the button on your content view by setting the frame property of the button. Then also subclass willTransitionToState: and check if the state is UITableViewCellStateShowingEditControlMask. If that's the case make the button visible. If not hide it.
Note: If you add an additional button to the UITableViewCell you also need to adjust the textLabel frame and other stuff to not overlap the button's rectangle.
cell.editingAccessoryType = UITableViewCellAccessoryCheckmark;
or some other value than "check"
or
cell.editingAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoDark];
or with some other value than the info button, with it's target set to something appropriate
an accessory view trumps a type

UITableViewCell's detaiTextLabel overlaps with custom subviews

I want to customize UITableViewCell by adding UILabel and two UIButton as its subview.
The cell style will be UITableViewCellStyleSubtitle and these three items would have to
next (on the left) of detailTextLabel.But when i do this, detailTextLabel overlaps with these items and display clipped or partial subviews.
Any way to handle out this without subclassing UITableViewCell if possible.
Thanks.
do you want to display something with detailTextLabel? If not you could try to hide it.
cell.detailTextLabel.hidden = YES;
otherwise you could add another Label at a better position which displays your detailText

How can I add a static background behind a UITableView programmatically?

I have a TableViewController and would like to have a static picture as a background, which doesn't scroll along.
The way that everyone recommends using
[UIColor colorWithPatternImage:[UIImage imageNamed:#"backgroundPattern.png"]]
doesn't work as it will
1.) move along and
2.) put the background pattern in every cell
I know how to do it in a XIB file (namely adding another layer underneath the TableView) but how do I do it programmatically from the TableViewController?
[myTblViewController.view insertSubview:myImageView belowSubview:myTblViewController.tableView];
That should work.
If it turns out that tableView is not a direct subview of the table view controller's main view, you can try:
[[myTblViewController.tableView superview] insertSubview:myImageView belowSubview:myTblViewController.tableView]; //Edited superview should be all lower case

how to create a cell view which has a button and a "shorter cell" like contacts app?

I haved tried to create a view with a UIButton and a tableView Cell,
then I set the header view to be this view.
However,the cell in the header is not rounded-rect, besides,how to handle the cell's event,when user click this cell.
I haved tried to use custom cell also, but how to create a button and a shorter cell in a row?
when you select the cell,will not affect the button state?
thanks.
You can fake this in a number of ways. The simplest is to layout a rounded rectangle UIButton in your header, and turn off userInteraction for it so that it's just decorative.