0

The Storyboard: http://s7.directupload.net/images/140717/z5hwmezv.png

Hey guys, Ive got an app that recursively triggers a the same tableview controller (lets say there are files and folders in it) until you trigger a file instead of a folder. When a file is clicked, it jumps into the GLKit View Controller.

Now I want to resize the tableView programmatically, which wont work. I already got the window size, which I'm going to use for calculation the position and size of the tableView:

CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

I tried different ways to change the size like the following, which dont change anything.

mainTableView.frame = CGRectMake(0, 0, screenWidth, screenHeight);

It works If I programmatically create the mainTableView, but then my segue gets deleted and I did not found any solution to create a segue programmatically.

It would be great if you can help me to find a solution that works with a storyboard tableView.

Cœur
  • 37,241
  • 25
  • 195
  • 267
r3n
  • 27
  • 6

2 Answers2

0

Step 1: Add delegate UITableViewDataSource,UITableViewDelegate

@interface viewController: UIViewController<UITableViewDataSource,UITableViewDelegate>
{
   UITableView *tableView;
}

Step 2:

-(void)viewDidLoad
{
tableView=[[UITableView alloc]init];
tableView.frame = CGRectMake(10,30,320,400);
tableView.dataSource=self;
tableView.delegate=self;
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
[tableView reloadData];
[self.view addSubview:tableView];

}

Step 3: Properties for tableview

//-- For table sections

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 1;
}

//-- For no of rows in table

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 10;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

//-- Table header height if needed

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   return 50;
}

//-- Assign data to cells

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier   forIndexPath:indexPath] ;

   if (cell == nil)
   {
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
   }
   cell.textLabel.text=[your_array objectAtIndex:indexPath.row]; ***(or)*** cell.textLabel.text = @"Hello";
   return cell;
}

//-- Operation when touch cells

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   // Your custom operation
}
Nazim
  • 64
  • 3
  • How does this answer attempt to answer the OP's question? – Warren Burton Jul 18 '14 at 15:02
  • Please add table view programatically. So I mentioned the way. – Nazim Jul 19 '14 at 15:11
  • Hey Nazim, thanks for your answer. I created the tableView programmatically. But now I got the problem, that my two segues where deleted as well. I dont know how to create a segue without the table in my storyboard :/ – r3n Jul 21 '14 at 09:31
  • I undid the deleting of the table and shrinked it to 0 height in the storyboardcontroller. Its now behind the programmatically created table and all segues are working fine. Not the perfect solution, but it works i guess? – r3n Jul 21 '14 at 09:43
0

Looking at your pic makes me think your CustomerListVC is a UITableView subclass which means the tableview is the root view and if you are using a UINavigationController based flow then you can't resize the root view readily.

What you can do is place the UITableView in a container and manipulate its constraints from the controller.

first change

class CustomerListVC : UITableViewController

to

class CustomerListVC : UIViewController

next throw away the Customer List instance in Interface Builder and drag in a new UIViewController instance instead. Xcode doesn't like you changing the base class of its stock objects.

make the new UIViewController instance a CustomerListVC type FileOwner and drag a UITableView into the content view.

Set edge constraints and add outlets to the constraints in your view controller.

enter image description here

From there play with the table as you see fit. e.g

-(void)squishAtBottomLeftAnimated:(BOOL)animate {

    CGFloat animateTime = animate? 0.5:0;

    [UIView animateWithDuration:animateTime animations:^{

        self.topEdgeConstraint.constant = 400;

        self.bottomEdgeConstraint.constant = 5;

        self.leadingEdgeConstraint.constant = 5;

        self.trailingEdgeConstraint.constant = 200;

        [self.view layoutIfNeeded];

    }];
}
Warren Burton
  • 17,451
  • 3
  • 53
  • 73
  • thanks for you answer. I Chose the solution of Nazim because it required less modification :) – r3n Jul 21 '14 at 09:44