connect button to TableViewController in xcode

后端 未结 5 1031
悲&欢浪女
悲&欢浪女 2020-12-07 00:19

I have a button in my view controller and I want to connect my button to table view controller (It means that when I click on button it loads and brings my table)

bu

5条回答
  •  温柔的废话
    2020-12-07 00:22

    FirstViewController.h

        #import 
    
        @interface FirstViewController : UIViewController
       
              {
                 UITableView *maintableView;
                 NSArray *tableData;
    
    
              }  
    
            @property (nonatomic,retain)IBOutlet UITableView *maintableView;
              -(IBAction)click;
    
           @end
    
              FirstViewController.m
    
                  #import "FirstViewController.h"
    
                  @implementation FirstViewController
                  @synthesise maintableView;
                    - (void)viewDidLoad
                        {
    
                        [maintableView setHidden : YES];
                        [super viewDidLoad];
    
                       }
    
                   - (void)viewDidUnload
                         {
                           [super viewDidUnload];
    
                         }
    
             - (BOOL)shouldAutorotateToInterfaceOrientation:     (UIInterfaceOrientation)interfaceOrientation
                      {
                if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
                         return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
                          } 
         else 
         {
              return YES;
              }
      -(IBAction)click
         {
              [maintableView setHidden : NO];
           tableData = [[NSArray alloc] initWithObjects:@"Johan", @"Paul",@"George",@"Ringo", nil];
           }
    
        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
          {
           return [tableData count];
    
           }
    
    
           - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
            {
                UITableViewCell *cell = nil;
    
               cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
            if(cell == nil)
              {
             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"];
    
             }
           cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    
           return cell;
       }
    
        }
        @end
    

提交回复
热议问题