IBAction on a button in Custom UITableViewCell

后端 未结 2 1849
忘掉有多难
忘掉有多难 2021-02-04 21:17

Using iOS 5 : : : I have a scenario where I must create a tableView with Custom Cells. The custom cells have a Controller called TainingCellController Subclass of UITableViewCel

2条回答
  •  粉色の甜心
    2021-02-04 22:23

    You will set your UITableViewCell's class to your CustomCell's class and you will defined IBoutlets in CustomCell class and connect them.

    And then you will set your Xib's file owner to your ViewController, and in your ViewController you will declare an

    IBOutlet CustomCell *yourClassLevelCell;
    

    and connect this IBOutlet to your Xib's UITableViewCell

    now when you will initilize the cell inside your ViewController's method cellForRowAtIndexPath you will add target manually, something like this:

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
       cell = yourClassLevelCell;
       [cell.button addTarget:self ... ];  
       //button is IBOutlet in your CustomCell class which you will have
       //connected to your Button in xib
    }
    

提交回复
热议问题