Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add the plus button to the right side of the table view in objective-c?

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.

like image 566
uttam Avatar asked Feb 16 '10 11:02

uttam


3 Answers

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;
like image 97
Thomas Leitz Avatar answered Oct 18 '22 12:10

Thomas Leitz


  1. Go to the iPhone Interface Guidelines Page.

  2. 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.

  3. 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;
    
like image 36
erastusnjuki Avatar answered Oct 18 '22 12:10

erastusnjuki


For Swift

let addButton = UIBarButtonItem.init(barButtonSystemItem: .Add,
                                     target: self,
                                     action: #selector(yourFunction))
self.navigationItem.rightBarButtonItem = addButton
like image 2
Dmitry Isaev Avatar answered Oct 18 '22 13:10

Dmitry Isaev