How to visually create and use static cells in a UITableView embedded in a UIViewController

后端 未结 6 996
深忆病人
深忆病人 2020-11-30 18:34

I\'m using XCode 4.2 and have built my UI using Storyboards. I need to create a view that has content above and below a UITableView and I can achieve this by using a UIViewC

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 19:03

    I know this is an old question but I have a scrappy solution to this issue.

    I needed 3 static cells on a UIViewController so this is what I did:

    1. Drag in some Table View Cells into your interface (not into UITableView) - add text and whatever else you need.
    2. Make IBOutlet properties for your cells and synthesise them.
    3. Drag a button and make it cover the entire cell. Set the button to type 'Custom' so it appears invisible - repeat for all cells
    4. Add numeric tags to your buttons
    5. Implement the following functions. buttonDown is connected to the buttons 'Touch Down' event. buttonUp is connected to 'Touch Up Inside' AND 'Touch Up Outside'

      -(IBAction)buttonDown:(id)sender {
          if ([sender tag] ==  1) {
              myFirstCell.selected = YES;
          }
          else if ([sender tag] ==  2) {
              mySecondCell.selected = YES;
          }
          else if ([sender tag] ==  3) {
              myThirdCell.selected = YES;
          }
      }
      
      -(IBAction)buttonUp:(id)sender {
          myFirstCell.selected = NO;
          mySecondCell.selected = NO;
          myThirdCell.selected = NO;
      }
      

    You can do whatever else you like in the buttonDown event and use the button to go directly to a new view. I find this pretty useful.

提交回复
热议问题