I want to add the plus button to right side of the table view to add the content of the that cell in other view.
how to add the plus button in the right side of the table view.
If you have a navigation bar you should add a UIBarButtonItem like this:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(addButtonPressed:)];
self.navigationItem.rightBarButtonItem = addButton;
Go to the iPhone Interface Guidelines Page.
Under "Standard Buttons for Use in Table Rows and Other User Interface Elements" Copy the ContactAdd button(I save it as ContactAdd.png here). Add it to your project.
In the cellForRowAtIndexPath:(NSIndexPath *)indexPath method add:
UIImage *image = [UIImage imageNamed:@"ContactAdd.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//You can also Use:
//UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
//match the button's size with the image size
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
// set the button's target to this table view controller so you can open the next view
[button addTarget:self action:@selector(yourFunctionToNextView:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
For Swift
let addButton = UIBarButtonItem.init(barButtonSystemItem: .Add,
target: self,
action: #selector(yourFunction))
self.navigationItem.rightBarButtonItem = addButton
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With