UA-17470720-3

Jump to content


Photo
- - - - -

How to customize UITableView list?


  • Please log in to reply
11 replies to this topic

#1 Horace Ho

Horace Ho

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 2
Good

Posted 03 May 2011 - 07:39 AM

By default, the UITableView list shows the first field, defined by definitionWithEntityName, in ascending order.

How to:

1) Combine 2 field values and shows list. E.g. I have Name and Gender, and I want to show Name (Gender) in the list, i.e. "Mr. Simpsons (M)", instead of "Mr. Simsons" only.

2) Listing by a different sorting order, e.g. Gender > Name

Thanks

#2 carl grainger

carl grainger

    Sr. Member

  • STV 3.0 Pro
  • PipPipPip
  • 44 posts
Reputation: 3
Good

Posted 03 May 2011 - 10:26 AM

Hi,

In simple cases you could just combine your field properties using ';' i.e.:

sCClassDefinition.titlePropertyName = @"Name;Gender";
sCClassDefinition.titlePropertyNameDelimiter = @" "; //(default)

however because you have bracketed the Gender field and because maybe the prefix could be Mr, Mrs, Miss, Ms etc depending on the gender, maybe you're looking at setting the cell up in the "willDisplayCell" methods of either the tableView delegate or the tableViewCell delegate.

Previous posts in the forum should help you with the sorting - maybe using NSPredicate with NSSortDescriptors.

I'm new here and still trying to get up to speed with STV but I hope this helps for a starter.

Cheers, Carl

#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 03 May 2011 - 07:35 PM

Hi Guys,

@Carl: perfectly said, thanks a lot!! :)

#4 Horace Ho

Horace Ho

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 2
Good

Posted 04 May 2011 - 04:40 AM

descriptionPropertyName does not support multiple values, right?

#5 Horace Ho

Horace Ho

    Jr. Member

  • STV 2.0
  • PipPip
  • 12 posts
Reputation: 2
Good

Posted 04 May 2011 - 04:42 AM

Hi Guys,

@Carl: perfectly said, thanks a lot!! :)


How about sorting order? Any way to customize the order or records shown in UITableView list? Thanks

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 04 May 2011 - 02:39 PM

Hi Horace,

As Carl mentioned earlier, you can fully control the sort order (and many other stuff) by providing STV with an NSPredicate. For a simple example on filtering using predicates, please refer to http://www.sensiblec...cope.html#2566. For more on NSPredicate, please refer to Apple's documentation.

#7 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 04 September 2011 - 09:04 AM

There have been a number of great changes to STV since this post series was made. Now we can have an "order by" attribute.

Question: is it possible to reverse the order without resorting to an NSPredicate method?

Thanks!!

#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 05 September 2011 - 05:45 PM

Hi David,

If all you need is just reverse the sorting order of your objects on the given key, just set your SCArrayOfObjectsSection 'sortItemsSetAscending' property to FALSE.

Hope this helps.

#9 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 05 September 2011 - 06:30 PM

Hi Tarek, I'm probably doing that wrong.

I have this code:

SCArrayOfObjectsSection *objectsSection = [SCArrayOfObjectsSection sectionWithHeaderTitle:nil
																	withEntityClassDefinition:taskDef];
	objectsSection.addButtonItem = self.navigationItem.rightBarButtonItem;
	   objectsSection.sortItemsSetAscending = FALSE;

I get this error:

*** Assertion failure in -[_UITableViewUpdateSupport _computeRowUpdates], /SourceCache/UIKit_Sim/UIKit-1906/UITableViewSupport.m:386
2011-09-06 00:00:05.741 taskApp[22906:fb03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to resolve row for index path: 2 indexes [0, 0]'



#10 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 05 September 2011 - 06:40 PM

Hi David,

I am not sure this has anything to do with sortItemsSetAscending. Is this the same project you're sending me?

#11 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 05 September 2011 - 06:48 PM

Hi Tarek, yes it is.

I only get the error with that code. Take it out and it works ok..

David

Ps. Thank you for all the help. I look forward to helping others.

#12 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 September 2011 - 01:29 PM

You're welome David :)

I did have a look at your app and this seems to be a glitch in STV. We'll fix this ASAP, thank you very much for reporting it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users