Leave A Comment With Json Wordpress in Xcode - ios

i made app with Xcode in swift using my Wordpress backend and getting data with json, i can show users comment on my app but i want that users can also leave comments in the app, there should be an option for Leave a comment on post details file, this is my code for showing comments
#IBAction func commentViewController(_ sender: Any) {
let vc = CommentViewController()
vc.dataArray = jsonData["comments"].array
self.navigationController!.pushViewController(vc, animated: true)
}
self.commentButton.layer.borderWidth = 2
self.commentButton.layer.borderColor = baseColor.cgColor
self.commentButton.layer.cornerRadius = 4.0
self.commentButton.tintColor = baseColor
self.commentButton.setTitle("comments(\(jsonData["comments"].array?.count ?? 0))", for: .normal)
but i don't know how to make a comment box where users can also leave comment , thanks
This Is My CommentViewController:
var tableView: UITableView = UITableView()
var dataArray: Array<JSON>!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Comments"
if #available(iOS 11.0, *) {
navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationItem.largeTitleDisplayMode = .automatic
let attributes = [
NSAttributedString.Key.foregroundColor : navigationBarTextColor, NSAttributedString.Key.font: UIFont(name: "SFUIText-Medium", size: 34),
]
navigationController?.navigationBar.largeTitleTextAttributes = attributes as [NSAttributedString.Key : Any]
} else {
// Fallback on earlier versions
}
// Check if Post have comments
if(self.dataArray.count == 0){
self.view.backgroundColor = UIColor(red: 216 / 255, green: 216 / 255, blue: 216 / 255, alpha: 1.0)
let label = UILabel(frame: CGRect(x: (UIScreen.main.bounds.width/2)-100, y: (UIScreen.main.bounds.height/2)-50, width: 200, height: 50))
label.text = "No Comments"
label.font = UIFont(name: "SFUIText-Regular", size: 18)
label.textAlignment = NSTextAlignment.center
self.view.addSubview(label)
}
else{
self.setupTable()
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getDateFromString(String:String) -> String{
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateObj = dateFormatter.date(from: String)
dateFormatter.dateFormat = "yyyy-MM-dd"
return dateFormatter.string(from: dateObj!)
}
func setupTable(){
tableView = UITableView(frame: UIScreen.main.bounds, style: UITableView.Style.plain)
tableView.delegate = self
tableView.dataSource = self
tableView.register(UINib(nibName: "commentViewCell", bundle: nil), forCellReuseIdentifier: "cell")
tableView.frame.size.height = UIScreen.main.bounds.height - 64
tableView.bounces = false
tableView.allowsSelection = false
self.view.addSubview(self.tableView)
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! commentViewCell
cell.commentText.text = String(htmlEncodedString: dataArray[indexPath.row]["content"].stringValue)
cell.name.text = String(htmlEncodedString:dataArray[indexPath.row]["name"].stringValue)
cell.date.text = getDateFromString(String: dataArray[indexPath.row]["date"].stringValue)
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
}

So you have a "tableView" field where all comments are shown.
As Joakim Danielson advices, you should add UITextView to the bottom of your screen.
Because the table view can be too long to fit the screen height, it probably will be scrolled, so it's easier to add this text view as a cell.
So you can do this in a following way:
Change the size of tableView for leaving the comment at the end:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.dataArray.count + 1
}
Add the cell with text view, let's name it LeaveCommentCell
Return the LeaveCommentCell instance as the last cell:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
if indexPath.row == self.dataArray.count { // this is the last row
let cell = tableView.dequeueReusableCell(withIdentifier: "AddCommentCell", for: indexPath) as! LeaveCommentCell // your new cell
return cell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "ShowCommentCell", for: indexPath) as! commentViewCell // please note identifiers should differ
cell.commentText.text = String(htmlEncodedString: dataArray[indexPath.row]["content"].stringValue)
cell.name.text = String(htmlEncodedString:dataArray[indexPath.row]["name"].stringValue)
cell.date.text = getDateFromString(String: dataArray[indexPath.row]["date"].stringValue)
return cell
}
Add a button (e.g. with text "Post") to LeaveCommentCell, subscribe for event when it's pressed, get comment text and send it to server.

Related

I'm Creating an demo on Expandeble Tableview, Expanding is working Fine... But facing issue while didselect row is tapped

Expanding and Collapsing is working fine tableview, Only facing issue while didselect row is tapped, I'm getting same index evry time after selecting a row. I'm getting the same out put, I want to pass the data to next view but output isn't working properly.
Here's My Details...
My OutPut
My Model
struct ItemList {
var name: String
var items: [String]
var collapsed: Bool
init(name: String, items: [String], collapsed: Bool = false) {
self.name = name
self.items = items
self.collapsed = collapsed
}
}
My ViewController Class
class ViewController: UIViewController {
#IBOutlet weak var tableView: UITableView!
var sections = [ItemList]()
var items: [ItemList] = [
ItemList(name: "Mac", items: ["MacBook", "MacBook Air"]),
ItemList(name: "iPad", items: ["iPad Pro", "iPad Air 2"]),
ItemList(name: "iPhone", items: ["iPhone 7", "iPhone 6"])
]
override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
}
}
TableView Extension
extension ViewController:UITableViewDelegate,UITableViewDataSource{
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 60
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerHeading = UILabel(frame: CGRect(x: 5, y: 10, width: self.view.frame.width, height: 40))
let imageView = UIImageView(frame: CGRect(x: self.view.frame.width - 30, y: 20, width: 20, height: 20))
if items[section].collapsed{
imageView.image = UIImage(named: "collapse")
}else{
imageView.image = UIImage(named: "expand")
}
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 60))
let tapGuesture = UITapGestureRecognizer(target: self, action: #selector(headerViewTapped))
tapGuesture.numberOfTapsRequired = 1
headerView.addGestureRecognizer(tapGuesture)
headerView.backgroundColor = UIColor.red
headerView.tag = section
headerHeading.text = items[section].name
headerHeading.textColor = .white
headerView.addSubview(headerHeading)
headerView.addSubview(imageView)
return headerView
}
func numberOfSections(in tableView: UITableView) -> Int {
return items.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
let itms = items[section]
return !itms.collapsed ? 0 : itms.items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->
UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
cell.textLabel?.text = items[indexPath.section].items[indexPath.row]
return cell
}
#objc func headerViewTapped(tapped:UITapGestureRecognizer){
print(tapped.view?.tag)
if items[tapped.view!.tag].collapsed == true{
items[tapped.view!.tag].collapsed = false
}else{
items[tapped.view!.tag].collapsed = true
}
if let imView = tapped.view?.subviews[1] as? UIImageView{
if imView.isKind(of: UIImageView.self){
if items[tapped.view!.tag].collapsed{
imView.image = UIImage(named: "collapsed")
}else{
imView.image = UIImage(named: "expand")
}
}
}
tableView.reloadData()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let row = items[indexPath.row]
print("IndexPath :- \(row.name)")
}
}
If you look at the way you are setting the text in your cells in cellForRowAt:
cell.textLabel?.text = items[indexPath.section].items[indexPath.row]
You are saying:
get the ItemList object for indexPath.section from items array
get the String from that object's items array of this indexPath.row
However, in your didSelectRowAt:
let row = items[indexPath.row]
print("IndexPath :- \(row.name)")
You are saying:
get the ItemList object for indexPath.row from items array
print the .name property of that object
So, change your didSelectRowAt code to match your cellForRowAt logic:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let selectedString = items[indexPath.section].items[indexPath.row]
print("IndexPath :- \(selectedString)")
// or, for a little more clarity
let sectionObject = items[indexPath.section]
let rowItem = sectionObject.items[indexPath.row]
print("IndexPath :- \(indexPath) // Section :- \(sectionObject.name) // Item :- \(rowItem)")
}

TableView Collapse, why it's sticking up like this?

I'm setting up a collapsable tableView, but something strange happens on the collapsable item. When you look at the video keep an eye on the "Where are you located" line.. (I'm using a .plist for the question and answer items)
Where do I go wrong, is it somewhere in my code? I don't want to let that line stick on the top :(
Here is the code I'm using but I can't find anything strange...
class FAQViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var questionsArray = [String]()
var answersDict = Dictionary<String, [String]>() // multiple answers for a question
var collapsedArray = [Bool]()
#IBOutlet weak var tableView: UITableView!
override func viewWillAppear(_ animated: Bool) {
// Hide the navigation bar on the this view controller
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
addTableStyles()
readQAFile()
tableView.delegate = self
tableView.dataSource = self
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
}
func addTableStyles(){
navigationController?.isNavigationBarHidden = false
self.tableView?.backgroundView = {
let view = UIView(frame: self.tableView.bounds)
return view
}()
tableView.estimatedRowHeight = 43.0;
tableView.rowHeight = UITableView.automaticDimension
tableView.separatorStyle = UITableViewCell.SeparatorStyle.singleLine
}
func readQAFile(){
guard let url = Bundle.main.url(forResource: "QA", withExtension: "plist")
else { print("no QAFile found")
return
}
let QAFileData = try! Data(contentsOf: url)
let dict = try! PropertyListSerialization.propertyList(from: QAFileData, format: nil) as! Dictionary<String, Any>
// Read the questions and answers from the plist
questionsArray = dict["Questions"] as! [String]
answersDict = dict["Answers"] as! Dictionary<String, [String]>
// Initially collapse every question
for _ in 0..<questionsArray.count {
collapsedArray.append(false)
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return questionsArray.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
if collapsedArray[section] {
let ansCount = answersDict[String(section)]!
return ansCount.count
}
return 0
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
// Set it to any number
return 70
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if collapsedArray[indexPath.section] {
return UITableView.automaticDimension
}
return 2
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = UIView(frame: CGRect(x:0, y:0, width:tableView.frame.size.width, height:40))
headerView.tag = section
let headerString = UILabel(frame: CGRect(x: 10, y: 10, width: tableView.frame.size.width, height: 50)) as UILabel
headerString.text = "\(questionsArray[section])"
headerView .addSubview(headerString)
let headerTapped = UITapGestureRecognizer (target: self, action:#selector(sectionHeaderTapped(_:)))
headerView.addGestureRecognizer(headerTapped)
return headerView
}
#objc func sectionHeaderTapped(_ recognizer: UITapGestureRecognizer) {
let indexPath : IndexPath = IndexPath(row: 0, section:recognizer.view!.tag)
if (indexPath.row == 0) {
let collapsed = collapsedArray[indexPath.section]
collapsedArray[indexPath.section] = !collapsed
//reload specific section animated
let range = Range(NSRange(location: indexPath.section, length: 1))!
let sectionToReload = IndexSet(integersIn: range)
self.tableView.reloadSections(sectionToReload as IndexSet, with:UITableView.RowAnimation.fade)
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cellIdentifier = "Cell"
let cell: UITableViewCell! = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier)
cell.textLabel?.adjustsFontSizeToFitWidth = true
cell.textLabel?.numberOfLines = 0
let manyCells : Bool = collapsedArray[indexPath.section]
if (manyCells) {
let content = answersDict[String(indexPath.section)]
cell.textLabel?.text = content![indexPath.row]
}
return cell
}
override var prefersStatusBarHidden: Bool {
return true
}
}
You need to change the style of the tableView to grouped, when you initialize it:
let tableView = UITableView(frame: someFrame, style: .grouped)
or from Storyboard:
After that you will have this issue, which I solved by setting a tableHeaderView to the tableView that has CGFloat.leastNormalMagnitude as its height:
override func viewDidLoad() {
super.viewDidLoad()
var frame = CGRect.zero
frame.size.height = .leastNormalMagnitude
tableView.tableHeaderView = UIView(frame: frame)
}
Just remove your headerView from view hierarchy here
#objc func sectionHeaderTapped(_ recognizer: UITapGestureRecognizer) {
headerView.removeFromSuperview()
...
}
By the way, yes creating a openable tableview menu with using plist is one of the methods but it could be more simple. In my opinion you should refactor your code.

Cosmic Mind - How to resize view when TabsController is implemented

I am having a problem on inserting a title to this screen.
How can I resize this view?
Here's my code where the TabsController is implemented:
class DashboardViewController: TabsController {
let screenSize = UIScreen.main.bounds
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare() {
super.prepare()
tabBar.lineColor = UIColor.CustomColor.blue
tabBar.setTabItemsColor(UIColor.CustomColor.grey, for: .normal)
tabBar.setTabItemsColor(UIColor.CustomColor.blue, for: .selected)
tabBarAlignment = .top
tabBar.tabBarStyle = .auto
tabBar.dividerColor = nil
tabBar.lineHeight = 2.0
tabBar.lineAlignment = .bottom
tabBar.backgroundColor = .white
}
}
Here's my option one code (and the option two code is the same):
class TeamProjectViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
prepareTabItem()
setupTableView()
}
fileprivate func setupTableView() {
tableView.backgroundColor = .white
tableView.allowsSelection = false
tableView.separatorColor = UIColor.CustomColor.lightGrey
tableView.register(UINib(nibName: "ProjectTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ProjectTableViewCell
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
}
extension TeamProjectViewController {
fileprivate func prepareTabItem() {
tabItem.title = "Option 1"
}
}
And here's what's happening to my tabs:
Thank you!
In your code you do not have anywhere where you are actually setting a view over the TabsController, where a title could exist. You would need to wrap the TabsController in order to accomplish this. One way, is use a ToolbarController:
let toolbarController = ToolbarController(rootViewController: myTabsController)
toolbarController.toolbar.title = "my title"
This is one way of going about your issue.
If you want just 20 pixels to move the tabs below status bar you can use StatusBarController with displayStyle = .partial. That's how I workaround.
let tabsController = TabsController(viewControllers: [
MyViewController1(),
MyViewController2()
])
let statusBarController = StatusBarController(rootViewController: tabsController)
statusBarController .displayStyle = .partial
// add statusBarController to hierarchy

How can I use the selectedIndex of a segmentedControl to get the corresponding index of array

My code:
class HomeViewController: UITableViewController {
var segmentedControl: HMSegmentedControl!
var text = [
// 名词
["音读名词","训读名词","音读与训读的分辨方法"],
// 形容词
["如何分辨形容词", "常用形容词", "形容词的变形规则"]
]
override func viewDidLoad() {
super.viewDidLoad()
configForSegmentedControl()
}
func configForSegmentedControl() {
segmentedControl = HMSegmentedControl(sectionTitles: ["名词","形容词","形容动词","片假名单词","动词","复合动词"])
segmentedControl.frame = CGRectMake(0, 0, self.view.bounds.width, 44)
segmentedControl.segmentEdgeInset = UIEdgeInsetsMake(0, 10, 0, 10)
segmentedControl.selectionStyle = HMSegmentedControlSelectionStyleFullWidthStripe
segmentedControl.selectionIndicatorLocation = HMSegmentedControlSelectionIndicatorLocationDown
segmentedControl.addTarget(self, action: #selector(HomeViewController.segmentedControlChangedValue(_:)), forControlEvents: UIControlEvents.ValueChanged)
if let font = UIFont(name: "BigYoungMediumGB2.0", size: 15) {
segmentedControl.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.blackColor(), NSFontAttributeName: font]
}
segmentedControl.backgroundColor = UIColor.whiteColor()
segmentedControl.selectionIndicatorHeight = 3
segmentedControl.selectionIndicatorColor = UIColor.blackColor()
tableView.tableHeaderView = segmentedControl
}
func segmentedControlChangedValue(segmentedControl: HMSegmentedControl) {
print("Selected index \(segmentedControl.selectedSegmentIndex) (via UIControlEventValueChanged)")
}
}
extension HomeViewController {
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return text[segmentedControl.selectedSegmentIndex].count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
print("cellForRowAtIndexPath:\(segmentedControl.selectedSegmentIndex)")
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = text[segmentedControl.selectedSegmentIndex][indexPath.row]
return cell
}
}
And here is the console output:
cellForRowAtIndexPath:0
cellForRowAtIndexPath:0
cellForRowAtIndexPath:0
Selected index 1 (via UIControlEventValueChanged)
Selected index 0 (via UIControlEventValueChanged)
The cellForRowAtIndexPath gets called before the segmentedControlChangedValue which is why I can't get the correct index to get the element of text array. So what should I do?
For future reference from comment:
If you want value in cellForRow, then you should reload the tableview inside that 'segmentedControlChangedValue'
In general case to set the the cell based on the selection/action, you should reload /beginUpdates the tableview as per requirement

Two UITableView in single UIViewcontroller not working properly

I want to implement following functionality in app show pict
But i have following problem show another pict
my code as follow
// MARK: UITextFieldDelegate Methods
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if str == "Loading"{
return 0
}else if tableView == tbl2{
return arrSub.count
}else{
return self.displayData.count
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:customCellInvitation = self.tableView.dequeueReusableCellWithIdentifier("cell")as! customCellInvitation
if tableView == tbl2{
//Code for the load secind table
cell.lblUserName.text = self.arrSub.objectAtIndex(indexPath.row).valueForKey("username") as?String
cell.btnAdd.setImage(UIImage(named: "yes1.png"), forState:(UIControlState.Normal))
return cell
}else{
//Code for the load first table
cell.lblUserName.text = self.displayData.objectAtIndex(indexPath.row).valueForKey("username") as?String
cell.btnAdd.setImage(UIImage(named: "add.png"), forState:(UIControlState.Normal))
cell.btnAdd.setImage(UIImage(named: "yes1.png"), forState:(UIControlState.Selected))
cell.btnAdd.addTarget(self, action: "addData:", forControlEvents: .TouchUpInside)
cell.btnAdd.tag = indexPath.row
}
return cell
}
// MARK: UITableViewDelegate Methods
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 44
}
//function call when user click Plus button
func addData(sender: UIButton!) {
arrSub .addObject(self.displayData .objectAtIndex(sender.tag))
var button:UIButton = sender.viewWithTag(sender.tag) as! UIButton
button.selected=true
button.userInteractionEnabled = false
NSLog("%#", arrSub)
[tbl2 .reloadData()]
}
I would suggest you to move your tableView Datasource and Delegate to separate classes. This is not a good practise at all. You will certainly mess up with your code.
What you are doing make code complexity, you can add you own custom class for tableView and can maintain it it all delegate datasource methods.Add that tableview in current class and with giving frame to it. By this you can add as many number of tableview to a single class and no need to worry about data handling.
Put a frame to this table view, then you can add two frame to a view controller. So add this frame to your view controller, you should adjust the frame width and hight in order to show two tables.
class ViewController: UIViewController {
lazy var tableView: UITableView = {
let tableView = UITableView()
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .None
tableView.frame = CGRectMake(20, (self.view.frame.size.height - 54 * 5) / 2.0, (self.view.frame.size.width - 25 * 5), 54 * 5)
tableView.autoresizingMask = .FlexibleTopMargin | .FlexibleBottomMargin | .FlexibleWidth
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.opaque = false
tableView.backgroundColor = UIColor.clearColor()
tableView.backgroundView = nil
tableView.bounces = false
tableView.showsVerticalScrollIndicator = true
return tableView
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.clearColor()
view.addSubview(tableView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// MARK : TableViewDataSource & Delegate Methods
extension LeftMenuViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 54
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell
let titles: [String] = ["Home", "Features", "Pricing", "Help", "About Us", "Contact Us"] // put your titles
let images: [String] = ["IconHome", "IconCalendar", "IconProfile", "IconSettings", "IconEmpty", "IconEmpty"] // add images if you want
cell.backgroundColor = UIColor.clearColor() // optional
cell.textLabel?.font = UIFont(name: "HelveticaNeue", size: 21)
cell.textLabel?.textColor = UIColor.whiteColor()
cell.textLabel?.text = titles[indexPath.row]
cell.selectionStyle = .None
cell.imageView?.image = UIImage(named: images[indexPath.row])
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
switch indexPath.row {
case 0:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewControllerWithIdentifier("TabBar") as! UIViewController
sideMenuViewController?.contentViewController = viewController
sideMenuViewController?.hideMenuViewController()
break // show table navigation view controller
case 1:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewControllerWithIdentifier("TabBar") as! UIViewController
sideMenuViewController?.contentViewController = viewController
sideMenuViewController?.hideMenuViewController()
break // show table navigation view controller
default:
break
}
}
}
// MARK: UITextFieldDelegate Methods
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:customCellInvitation = self.tableView.dequeueReusableCellWithIdentifier("cell")as! customCellInvitation
if tableView == tbl2{
cell.lblUserName.text = self.arrSub.objectAtIndex(indexPath.row).valueForKey("username") as?String
if str = "yes"{
cell.btnAdd.setImage(UIImage(named: "yes1.png"), forState:(UIControlState.Normal))
}else{
cell.btnAdd.setImage(UIImage(named: "NO.png"), forState:(UIControlState.Normal))
}
return cell
}else{
cell.lblUserName.text = self.displayData.objectAtIndex(indexPath.row).valueForKey("username") as?String
if str = "yes"{
cell.btnAdd.setImage(UIImage(named: "yes1.png"), forState:(UIControlState.Normal))
}else{
cell.btnAdd.setImage(UIImage(named: "NO.png"), forState:(UIControlState.Normal))
}
}
return cell
}

Resources