How to insert items to a UITableView when a UIButton is clicked in iOS

前端 未结 2 443
甜味超标
甜味超标 2021-01-14 06:28

I have been practicing with tableViews but I cannot figure out how to insert new items when a button is clicked.

This is what I have:

BIDViewControlle

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-14 07:33

    You are doing it right,

    - (IBAction)addItems:(id)sender {
        // I thought it was as simple as this, but it doesn't work
        [self.names addObject:@"Brad"];
        [self.tableView relaodData];
    }
    

    is the correct way.

    Please double check the variable tableView, I can't see the declaration of it.

    make sure you have,

    @property(weak, nonatomic) IBOutlet UITableView *tableView;
    [self.tableView setDelegate:self];
    [self.tableView setDataSource:self];
    

    and properly connected the tableView to .nib

提交回复
热议问题