iPad’s are perfect for consuming content, and some of the best (and most popular) apps are News feed type apps. So we’ve created an app template that’s a perfect aggregator for WordPress feeds, News feeds and RSS feeds. It’s custom design features both beautiful portrait and landscape views, which has a content first UX, with nice iOStouches like drop down blurs and outlined Menu logos.
//
// MasterViewController.swift
// News-iPad
//
// Created by MyAppTemplatesTeam on 08/10/14.
// Copyright (c) 2014 MyAppTemplates. All rights reserved.
//
import UIKit
class MasterViewController: UIViewController {
var detailViewController: UINavigationController? = nil
var items = NSMutableArray()
var users = NSMutableArray()
var themeBtnArray = NSMutableArray()
var socialBtnArray = NSMutableArray()
@IBOutlet var tblContents : UITableView!
@IBOutlet var tblUsers : UITableView!
@IBOutlet var themeBtnGreen : UIButton!
@IBOutlet var themeBtnRed : UIButton!
@IBOutlet var themeBtnBlue : UIButton!
@IBOutlet var themeBtnBlack : UIButton!
@IBOutlet var btnFacebook : UIButton!
@IBOutlet var btnTwitter : UIButton!
override func awakeFromNib() {
super.awakeFromNib()
self.preferredContentSize = CGSize(width: 320.0, height: 600.0)
}
override func viewDidLoad() {
super.viewDidLoad()
let controllers = self.splitViewController!.viewControllers
self.detailViewController = controllers[controllers.count-1].topViewController as? UINavigationController
self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
var appDelegate : AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate!
if ((self.interfaceOrientation == UIInterfaceOrientation.Portrait) || (self.interfaceOrientation == UIInterfaceOrientation.PortraitUpsideDown)) {
appDelegate.isCollapsed = false
} else {
appDelegate.isCollapsed = true
}
items.addObject(["icon":"icon-menu-list.png","title":"Home"])
items.addObject(["icon":"icon-menu-list.png","title":"Living"])
items.addObject(["icon":"icon-menu-list.png","title":"Tech & Science"])
items.addObject(["icon":"icon-menu-list.png","title":"Design"])
items.addObject(["icon":"icon-menu-list.png","title":"Sports"])
items.addObject(["icon":"icon-star.png","title":"Favourites"])
users.addObject(["icon":"popup-favourite-pic1_ls.png","name":"Kristen Wilkinson","Location":"New York"])
users.addObject(["icon":"popup-favourite-pic1_ls.png","name":"Phil McKlain","Location":"London"])
users.addObject(["icon":"popup-favourite-pic1_ls.png","name":"Shandra Sven","Location":"Chicago"])
users.addObject(["icon":"popup-favourite-pic1_ls.png","name":"Marc Jhonson","Location":"Los Angeles"])
themeBtnArray.addObject(themeBtnGreen)
themeBtnArray.addObject(themeBtnRed)
themeBtnArray.addObject(themeBtnBlue)
themeBtnArray.addObject(themeBtnBlack)
socialBtnArray.addObject(btnFacebook)
socialBtnArray.addObject(btnTwitter)
// self.performSegueWithIdentifier("showNews", sender: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table View
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (tableView == tblContents) {
return items.count
} else {
return users.count + 1
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if (tableView == tblContents) {
var cell: MasterItemTableViewCell = tableView.dequeueReusableCellWithIdentifier("ItemCell", forIndexPath: indexPath) as MasterItemTableViewCell
cell.imgIcon.image = UIImage(named:(items.objectAtIndex(indexPath.row)["icon"] as? String)!)
cell.lblTitle.text = items.objectAtIndex(indexPath.row)["title"] as? String
return cell
} else {
if (indexPath.row == users.count) {
var cell: LoadingTableViewCell = tableView.dequeueReusableCellWithIdentifier("LoadingCell", forIndexPath: indexPath) as LoadingTableViewCell
return cell
} else {
var cell: MasterUserTableViewCell = tableView.dequeueReusableCellWithIdentifier("UserCell", forIndexPath: indexPath) as MasterUserTableViewCell
cell.imgUser.image = UIImage(named:(users.objectAtIndex(indexPath.row)["icon"] as? String)!)
cell.lblName.text = users.objectAtIndex(indexPath.row)["name"] as? String
cell.lblLocation.text = users.objectAtIndex(indexPath.row)["Location"] as? String
return cell
}
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
NSLog("should be called once", 1)
if segue.identifier == "showNews" {
if let indexPath = self.tblContents.indexPathForSelectedRow() {
var navController : UINavigationController! = segue.destinationViewController as UINavigationController
var viewControllers : NSArray = navController.viewControllers as NSArray
var newsVC : NewsViewController! = viewControllers.objectAtIndex(0) as NewsViewController
newsVC.hideDetail()
}
} else if segue.identifier == "showSubscribe" {
self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden
var navController : UINavigationController! = segue.destinationViewController as UINavigationController
var viewControllers : NSArray = navController.viewControllers as NSArray
var subVC : SubscriptionsViewController! = viewControllers.objectAtIndex(0) as SubscriptionsViewController
subVC.hideDetail()
} else if segue.identifier == "showSettings" {
}
}
func showDetail() {
self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
var appDelegate : AppDelegate! = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.isCollapsed = true
}
func hideDetail (){
self.splitViewController?.preferredDisplayMode = UISplitViewControllerDisplayMode.PrimaryHidden
var appDelegate : AppDelegate! = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.isCollapsed = false
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (tableView == tblContents) {
self.performSegueWithIdentifier("showNews", sender: nil)
}
}
@IBAction func settingBtnTapped(sender: AnyObject) {
//settingsNav
var appDelegate : AppDelegate! = UIApplication.sharedApplication().delegate as AppDelegate
var settingNav = self.storyboard?.instantiateViewControllerWithIdentifier("settingsNav") as UINavigationController
appDelegate.setMasterViewController(settingNav)
}
@IBAction func themeSelected(sender: UIButton){
self.setSelected(sender, fromArray: themeBtnArray)
}
@IBAction func socialBtnSelected(sender: UIButton) {
self.setSelected(sender, fromArray: socialBtnArray)
}
func setSelected(button: UIButton, fromArray buttonArray:NSMutableArray){
for (index,buttonTemp) in enumerate(buttonArray) {
var button1 = buttonArray[index] as UIButton
button1.selected = false
}
button.selected = true
}
}