iOS App: Separator Lines And Back Button In Master-Detail Application

mainWhen you create a master-detail application in iOS, a few things appear by default. If you notice it, you will see that the empty cells are separated by lines. But we want the separator lines to appear for items that are there in the table. Also, you will notice that the back button in the detail view contains the title by default. What if we want it to say something else? Perhaps not say anything at all. How do we do it?  

Getting rid of the Separator Lines for empty cells

To get rid of them, add the following inside viewDidLoad() function in the master view .m file:

[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]];

There is also another way to do it. You can add the following function in the master view .m file. The only catch is that the last separator line will be appear only after you click the last item and come back to the master view:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{
// This will create an invisible footer
return 0.01f;
}

Customizing the Back Button

To customize the back button in the detail view, place the following in the viewDidLoad() method in the master .m file:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"My Title" style:UIBarButtonItemStyleBordered target:nil action:nil];

Note that you need to do this in the view controller one level up the stack. In other words, don’t do this in the visible view controller. Instead, do it in the view controller that you’d see if you hit the back button. As we can see, we want to back button to change in the detail view and so we are modifying the master .m file.

————————————————————————————————-

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s