JoshDG
JoshDG

Reputation: 3931

iOS: Replace IBOutlet with new view

I have a UITableView that I created in IB and has an outlet tblHome in my view controller. I want to have it such that if the user is not running iOS7, then the table will be plain (it is set as grouped in IB).

I know that you can't change the style once its been created, so I'll have to change it. How can I replace the existing table with a new one?

The following did not work

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7)
{
    tblHome = [[UITableView alloc] initWithFrame:CGRectMake(tblHome.frame.origin.x, tblHome.frame.origin.y, tblHome.frame.size.width, tblHome.frame.size.height) style:UITableViewStylePlain];
}

Upvotes: 0

Views: 236

Answers (2)

freelancer
freelancer

Reputation: 1658

You set the table style when you initialize the tableview.

USE UITableView programmatically like below

 NSArray *vComp = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
if ([[vComp objectAtIndex:0] intValue] >= 7){
    tblHome = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStyleGrouped];
 }
else{
     tblHome = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 480) style:UITableViewStylePlain];
}

Upvotes: 1

alexgophermix
alexgophermix

Reputation: 4279

There isn't enough information here yet. Where are you doing this check and overwrite?

If you don't use initWithNibName: to initialize your UIViewController it won't pull the settings from IB and you'll have to add the tableView manually via addSubview:

Step through your code with the debugger and make sure that on a sub iOS 7 device the line actually gets executed as expected.

Upvotes: 0

Related Questions