UA-17470720-3

Jump to content


Photo
- - - - -

Search Controller Makes First Section in TableView Show Basic Cells


  • Please log in to reply
2 replies to this topic

#1 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 19 January 2015 - 02:58 PM

Greetings Programs!

 

Here's something odd. I have this tableview which I use for selecting a category but I am getting my first section showing up as a basic cell and the remaining using the custom cell.

 

Have a look at the pictures; the first picture shows what's happening. The second picture shows what happens if I comment out "objectsModel.enableSearchController = true". The last picture shows what happens if I enableSearchController but remove the sectionHeaderTitleForItem action.

 

In my IB, I have a tableview with an SCArrayOfObjectsSection with no data definition.

 

class CategoryListViewController: SCTableViewController {
	
	@IBOutlet var sortBy: UISegmentedControl!

	override func viewDidLoad() {
		super.viewDidLoad()
		
		displayView()
	}
	
	func displayView() {
		
		self.navigationBarType = SCNavigationBarType.None;
        
		var objectsModel = SCArrayOfObjectsModel(tableView: self.tableView, items: Global.variables.site.categories, itemsDefinition: nil)
		objectsModel.enableSearchController = true
		self.tableViewModel = objectsModel
        
		self.tableViewModel.modelActions.sectionHeaderTitleForItem = {
			(itemsModel, item, itemIndex)->String in
			
			switch weak_self.sortBy.selectedSegmentIndex
			{
                case 1:
                    // Sort by name.
                    return (item.valueForKey("name") as String).leftString(1).uppercaseString
                default:
                    // By default or selectedSegmentIndex = 0 sort by category.
                    return (item.valueForKey("parentCategoryName") as String).uppercaseString
			}
		}
        
		self.tableViewModel.sectionActions.didFetchItemsFromStore = {
			(itemsSection, items) in
			
			itemsSection.fetchItemsCell = nil;
			
			// This is not the only way to sort, but probably the easiest when using STV
			var fetchOptions:SCDataFetchOptions
			
			switch weak_self.sortBy.selectedSegmentIndex
			{
                case 1:
                    fetchOptions = SCDataFetchOptions(sortKey: "name", sortAscending: false, filterPredicate: nil)
                default:
                    fetchOptions = SCDataFetchOptions(sortKey: "categoryOrder", sortAscending: true, filterPredicate: nil)
                    break;
			}
			
			fetchOptions.sortMutableArray(items)
		}

		self.tableViewModel.cellActions.willDisplay = {
			(cell, indexPath) in
			
			if cell.isKindOfClass(SCCustomCell) && cell.boundObject != nil
			{
				cell.accessoryType = UITableViewCellAccessoryType.None
				let category = cell.boundObject.valueForKey("name") as String
			}
		}
	}
}

 

Thoughts?

 

Wg

Attached Files


Edited by wizgod, 19 January 2015 - 03:07 PM.

P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)


#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 20 January 2015 - 12:02 PM

Hi Wg,

 

Very strange. Are you able to attach a sample?



#3 wizgod

wizgod

    I'm what you guys call a User

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 575 posts
  • LocationThe Grid
Reputation: 149
Popular

Posted 23 January 2015 - 01:16 PM

Hi Tarek!

 

I've PM'd you with it.

 

As I noted in the PM, for some reason, the stripped down version behaves differently than the full app. The category list shows all the cells correctly but in the first cell/section is a progress indicator. This progress indicator doesn't appear in the full app, and you see the result in the previous pictures.

 

Here's the image with the indicator: https://www.dropbox....G_8471.PNG?dl=0

 

 don't know what's causing it, I used a copy of the full app and stripped it down and didn't create a new one.

 

Wg


P.S. I love Swift... talk Swift.. Never too old school to learn yet another programming language. LOL! ;-)





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users