I would like to draw my own edit accessory view instead of the red minus button in a UITableView.
Strangely setting any of them in tableView: cellForRowAtIndexPath: has no effect
cell.editingAccessoryType = UITableViewCellAccessoryNone;
cell.editingAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"cancel"]];
since the button is set before calls to that.
Thank you
In order for the editing controls to be seen, editing needs to be enabled in the table view.
Try sending this to the table view: - (void)setEditing:(BOOL)editing animated:(BOOL)animate.
http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UITableView_Class/Reference/Reference.html#//apple_ref/occ/instm/UITableView/setEditing:animated:
Related
I have added a UIImageView to the right side of the content view of my UITableViewCell.
I am trying to prevent the cell from being highlighted while the user is touching the UIImageView (because an attached gesture recognizer performs some other functionality).
I have thought about implementing tableView:shouldHighlightRowAtIndexPath: and returning NO, but I am unsure how to easily determine if the image is being touched when this method is called. Is there an easy way to do this?
Try this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
// Add tap gesture recogniser to cell's image view
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(tapped)];
tap.cancelsTouchesInView = YES;
cell.theImageView.userInteractionEnabled = YES;
[cell.theImageView addGestureRecognizer:tap];
return cell;
}
The important parts are to make sure the image view has userInteractionEnabled = YES and the gesture recogniser has cancelsTouchesInView = YES.
This will cause the tapped method to fire if the image view is tapped, but the cell will not be highlighted.
why don't you add a UIButton with type custom.Will have the tap button action.Will not affect the cell highlight
Prevent highlight of tablecell
cell.selectionStyle = UITableViewCellSelectionStyleNone;
or
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
I have grouped table view. I want to add UISegmentedControl in table cell with clear background so that it will be displayed as FOOTER . How can I do this? I tried using clearColor. But it's not working.
Set the background view with a clear UIView object like so:
UIView *clearView = [[UIView alloc] initWithFrame:CGRectZero];
[clearView setBackgroundColor:[UIColor clearColor]];
[self setBackgroundView:clearView];
[clearView release];
And make sure you set cell selection style to none.
Edit: added some square brackets
So I'm creating a settings page in my app and up to now I've set it up with a grouped table view with both group titles and settings/cell tiles.
At this point I'd like to add UISwitches (Already have their properties set up) to each cell. How can I do that?
The easiest way is to add a UISwitch as the accessory view for the UITableViewCell.
UISwitch* aswitch = [[UISwitch alloc] initWithFrame:CGRectZero];
aswitch.on = YES; // or NO
cell.accessoryView = aswitch;
[aswitch release];
I'm looking for opinions on the best way to implement the following functionality. I have a UIViewController with a UITableView in Grouped Format. Each TableViewCell contains an NSString. When the User taps on a cell I'd like to in my didSelectRowForIndexPath method popup a UIView with a single textfield, that's prepopulated with the NSString in the given cell that was selected. The reason for displaying the UIVIew is I want it to be about 280 x 380 frame and still see some of the UITableView.
The goal being that it behaves like a ModalViewController except for the iPhone. Does anyone have any suggestions on how to implement this behavior or if there is a better implementation?
Create the UIView (with the UITextField inside) beforehand, and make it hidden:
// Of course, these instance variable names are made up, and should be changed
self.myModalView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 380)] autorelease];
[self.view addSubview:self.myModalView]
self.myTextField = [[[UITextField alloc] init] autorelease];
[self.myModalView addSubview:self.myTextField];
self.myModalView.hidden = YES;
Then, when the user selects a row, populate the text field and show the modal view:
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
// Replace stringAtIndexPath with however your data source accesses the string
NSString* myString = [self stringAtIndexPath:indexPath];
self.myTextField.text = myString;
self.myModalView.hidden = NO;
}
If you want to get fancy, you can do some CATransition stuff before showing the modal view.
I think you can use "addSubView" in UITableView. Add the ModalView to your UITableView directly. It will work.
Use some animation to implement this effect. When the UIView appears, it will lift the UITableView, like some keyboard behavior. So, you have to addSubView on the self.view and modify the UITableView's frame. And, the UITableView should be a child view of self.view, if self.view is the same as the UITableView, then you has no self.view for adding this UIView.
Iam creating a custom TableView Cell Which has some text and a Background image. when i select the cell then the image should chnage but this is not hapening, i have use following code so some one help me?
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
if (selected)
[self.imgSelected setImage:[UIImage imageNamed:#"listing-gradient-hover.png"]];//Image that i want on Selection
else
[self.imgSelected setImage:[UIImage imageNamed:#"listing-gradient.png"]];
//Normal image at background everytime table loads.
// Configure the view for the selected state
}
This is not working for me.
Try the following:
initialize an UIImageView to be the background view and an UIImageView to be the selected background view when you setup ypu custom table view cell:
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"listing-gradient-hover.png"]];
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"listing-gradient.png"]];
UITableViewCell adds the value of the selectedBackgroundView property as a subview only when the cell is selected. It adds the selected background view as a subview directly above the background view (backgroundView) if it is not nil, or behind all other views. Calling setSelected:animated: causes the selected background view to animate in and out with an alpha fade. You do not need to override this method just for switching the background image upon selection.