This question is locked. New answers and comments are not allowed.
In my side menu I'm using custom cells for the menu using the cellForItemAtIndexPath delegate method but when a user clicks on one of the cells that isn't interactive (I have two cells that are there purely for informational purposes so I set the selection style to None on both of them) the table view reloads and looses all of the custom styling from the cellForItemAtIndexPath and just shows each item in plain black text.
Here's some code that I have, not sure what you would need so just pasting chunks of it
func
sideDrawer
(sideDrawer: TKSideDrawer!, cellForItemAtIndexPath
indexPath
:
NSIndexPath
!) -> TKSideDrawerTableViewCell! {
let cell =
TKSideDrawerTableViewCell
(style:
UITableViewCellStyle
.Default
,
reuseIdentifier
:
"cell"
)
let section = sideDrawer
.sections
[indexPath
.section
] as! TKSideDrawerSection
let item = section
.items
[indexPath
.item
] as! TKSideDrawerItem
//the first section contains the rep name and location centered in the table
if
indexPath
.section
==
0
{
if
indexPath
.row
==
0
{
let centeredCell =
CenterLabelCell
()
centeredCell
.selectionStyle
=
UITableViewCellSelectionStyle
.None
centeredCell
.item
= item
return
centeredCell
}
else
if
indexPath
.row
==
1
{
let centeredImageAndTextCell =
CenterLabelWithImageCell
()
centeredImageAndTextCell
.selectionStyle
=
UITableViewCellSelectionStyle
.None
centeredImageAndTextCell
.item
= item
return
centeredImageAndTextCell
}
}
//the second section only needs a special cell if the row is selected
if
indexPath
.section
==
1
|| indexPath
.section
==
2
{
//get the currently selected index
let selectedDict =
NSUserDefaults
.standardUserDefaults
()
.objectForKey
(KeyValues
.keySelectedIndex
()) as!
NSDictionary
let currentIndex =
NSIndexPath
()
.convertDictToIndexPath
(selectedDict)
//set selected index to have tint on both image and text
if
indexPath == currentIndex {
let selectedCell =
SelectedTableCell
()
selectedCell
.item
= item
return
selectedCell
}
else
{
let regularCell =
NonSelectedTableCell
()
regularCell
.item
= item
return
regularCell
}
}
return
cell
}
and here's the code from the didSelectItemAtIndexPath method
func
sideDrawer
(sideDrawer: TKSideDrawer!, didSelectItemAtIndexPath
indexPath
:
NSIndexPath
!) {
//let section = sideDrawer.sections()[indexPath.section] as! TKSideDrawerSection
//let item = section.items()[indexPath.item] as! TKSideDrawerItem
let section = indexPath
.section
if
section ==
1
|| section ==
2
{
//first check if the person selected the same index that is currently being viewed
let indexDict =
NSUserDefaults
.standardUserDefaults
()
.objectForKey
(KeyValues
.keySelectedIndex
()) as!
NSDictionary
let previousIndex :
NSIndexPath
=
NSIndexPath
()
.convertDictToIndexPath
(indexDict)
if
previousIndex != indexPath {
//store selected index
NSUserDefaults
.standardUserDefaults
()
.setObject
(indexPath
.convertIndexPathToDict
(),
forKey
: KeyValues
.keySelectedIndex
())
//give the menu enough time to close before replacing the view with the new view
//self.performSelector("showNewViewController:", withObject: indexPath, afterDelay: 0.2)
let delay =
0
.25
let intDelay =
Int64
(
delay
*
Double
(
NSEC_PER_SEC
))
let popTime =
dispatch_time_t
(
dispatch_time
(DISPATCH_TIME_NOW, intDelay))
dispatch_after
(popTime,
dispatch_get_main_queue
(), { Void in
self
.showNewViewController
(indexPath)
})
//after any selection call the setup method again just to make sure the custom views stay the same
self
.setupSideMenu
()
}
}
}