Reputation: 1364
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.
Upvotes: 8
Views: 12739
Reputation: 3998
For Swift
let addButton = UIBarButtonItem.init(barButtonSystemItem: .Add,
target: self,
action: #selector(yourFunction))
self.navigationItem.rightBarButtonItem = addButton
Upvotes: 2
Reputation: 433
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;
Upvotes: 27
Reputation: 1511
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;
Upvotes: 9