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