UA-17470720-3

Jump to content


Photo
- - - - -

How to Add Custom Cell at the Begining of the TableView


  • Please log in to reply
27 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 17 October 2013 - 08:11 AM

Greetings Programs!

 

I have the following which adds the custom cell (which contains buttons for various actions) at the end of the tableview. It was all fine when the tableview didn't have more cells than could be viewable at one time. Alas, I had to add a couple o' more cells and you have to scroll to see the custom cell now.

 

How would I be able to add the cell to the top of the tableview?

 

	objectsModel.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
    {
		SCTableViewSection *actionSection = [SCTableViewSection section];
		SCCustomCell *actionCell = [SCCustomCell cellWithText:nil
										 objectBindingsString:nil
													  nibName:@"ActionCell"];
		
		[actionSection addCell:actionCell];
		[detailModel addSection:actionSection];
	};

 

Thanks!

 

Wg


  • Geraldsl likes this

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


#2 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 17 October 2013 - 08:57 AM

Hi wizgod,
 
Instead of:
 

[detailModel addSection:actionSection];

 
try:
 
 

[detailModel insertSection:actionSection atIndex:0];

HTH


  • Tarek, wizgod and mtamburro like this
Cheers,

Dave

www.dgapps.ie

#3 wizgod

wizgod

    I'm what you guys call a User

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

Posted 17 October 2013 - 07:26 PM

Thank you User :) !

 

Wg


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


#4 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 19 October 2013 - 03:50 AM

WG,

 

Thanks for the topic question. I was trying to do the opposite--i.e. add a custom cell to the end of the tableview, in lieu of the front. After 3 hours of searching I found your question --and your initial code snippet provided the solution, as usual.

 

TRG



#5 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 October 2013 - 08:29 AM

Hi guys,

It's also worth noting here that you can add your own custom cells anywhere in an SCArrayOfObjectsSection using the didFetchItemsFromStore section action (you will find a code sample doing exactly this in the docs link I provided).

HTH


  • wizgod likes this

#6 TODD GARLAND

TODD GARLAND

    Experienced Member

  • STV 4.0 Pro
  • PipPipPipPip
  • 69 posts
Reputation: 21
Excellent

Posted 20 October 2013 - 01:48 PM

WG,

 

When your custom cell was located at the end of the tableview, how did you access the data contained in the cell? For example, when I put the cell in front of the tableview, I can get the data, when I place at end and cursor into the cell text fields, the cell itself "grays" out in the simulator and even though I can place the data in the text field, the text field does not retain the data. So I am thinking the "grayed" out cell is essentially locked.

 

Thanks

 

TRG



#7 wizgod

wizgod

    I'm what you guys call a User

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

Posted 20 October 2013 - 07:52 PM

I was setting the bound object (actionCell.boundObject = order) as below:

 

	objectsModel.sectionActions.detailModelConfigured = ^(SCTableViewSection *section, SCTableViewModel *detailModel, NSIndexPath *indexPath)
    {
		ServiceOrder *order = (ServiceOrder *)[detailModel sectionAtIndex:0].boundObject;
		NSLog(@"Order id: %@ = %@", order.serviceOrderId, NextServiceOrderNumber);
		
		if ([order.serviceOrderId isEqualToString:NextServiceOrderNumber]) return;
		
		SCTableViewSection *actionSection = [SCTableViewSection section];
		SCCustomCell *actionCell = [SCCustomCell cellWithText:nil
										 objectBindingsString:nil
													  nibName:@"ActionCell"];
		actionCell.boundObject = order;
		actionCell.tag = 10;
		actionCell.cellActions.customButtonTapped = ^(SCTableViewCell *cell, NSIndexPath *indexPath, UIButton *button)
		{
			NSLog(@"Custom button with tag:%i has been tapped for cell at indexPath:%@.", button.tag, indexPath);
			
			switch (button.tag) {
				case 1:
					[self didSelectDelete];
					break;
					
				case 2:
					[self didSelectClone];
					break;
					
				case 3:
					[self didSelectHistory];
					break;
				
				case 4:
					[self didSelectHold];
					break;
					
				case 5:
					[self didSelectServiceDetails];
					break;
					
				case 6:
					[self showConfirmAlert:4 title:@"Post Service Order to Visual?"];
					break;
					
				case 7:
					[self didSelectInvoice];
					break;

				default:
					break;
			}
		};

		actionCell.cellActions.willDisplay = ^(SCTableViewCell *cell, NSIndexPath *indexPath)
		{
			if([cell isKindOfClass:[SCCustomCell class]])
			{
				// Delete the pdf invoice just in case it exists.
				if (weak_self.serviceOrder != nil) {
					[weak_self deleteFile:[NSString stringWithFormat:@"%@_Invoice.pdf", weak_self.serviceOrder.serviceOrderId]];
				}

				weak_self.actionCellIndexPath = indexPath;
				[weak_self configureActionButtons];
			}
		};
		
		[actionSection addCell:actionCell];
		// This adds at the end.
		[detailModel addSection:actionSection];
		// This adds at the begining.
		//[detailModel insertSection:actionSection atIndex:0];
	};

 

Also since I have the cell at the begining (not at the end as above) I had to change the sectionAtIndex to get the bound object at section 1:

ServiceOrder *order = (ServiceOrder *)[detailModel sectionAtIndex:1].boundObject;

 

Wg


Edited by wizgod, 20 October 2013 - 07:59 PM.

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


#8 David DelMonte

David DelMonte

    Forum Master

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

Posted 13 November 2014 - 06:22 PM

Hi all, is this the preferred behavior in STV4? Thanks

 

 

Hi wizgod,
 
Instead of:
 

[detailModel addSection:actionSection];

 
try:
 
 

[detailModel insertSection:actionSection atIndex:0];

HTH

 



#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 13 November 2014 - 06:42 PM

Hi David,

 

Sure, except that you can now also add the section right in Interface Builder if you wish.



#10 David DelMonte

David DelMonte

    Forum Master

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

Posted 13 November 2014 - 06:49 PM

OK, thanks Tarek.. Would this be the way to add a custom UIButton - i.e. something to be used outside of STV? Perhaps more broadly, how do I mix STV and non-STV objects in STV4 -- especially -- how to do this in IB?

 

On a similar subject, in STV4, how do I style (and rename) things like bar button items (+, Edit, Save, Done) in IB?



#11 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 17 November 2014 - 10:06 AM

I think what you're looking for using a regular SCViewController, dropping your UI regularly on it, then have STV exist on only a part of this view controller's view. Although you can't directly drop static UITableView's on non UITableViewControllers (this is an Apple limitation), you can still create everything normally in an SCTableViewController, then drop a "Container View" into your SCViewController and connect it to the SCTableViewController. If you're having trouble with this, please let me know and I'll create a sample app for you.


  • David DelMonte likes this

#12 David DelMonte

David DelMonte

    Forum Master

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

Posted 17 November 2014 - 10:10 AM

I think what you're looking for using a regular SCViewController, dropping your UI regularly on it, then have STV exist on only a part of this view controller's view. Although you can't directly drop static UITableView's on non UITableViewControllers (this is an Apple limitation), you can still create everything normally in an SCTableViewController, then drop a "Container View" into your SCViewController and connect it to the SCTableViewController. If you're having trouble with this, please let me know and I'll create a sample app for you.

 

Thanks Tarek, Would a sample for everyone -- how to integrate STV bits with non-STV bits -- have widespread appeal? What do others think? If not, I could surely appreciate a simple sample.



#13 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 27 November 2014 - 07:01 AM

Hi David,

 

Your requested sample is now bundled with all STV 4.0 packages. Thanks a lot for the suggestion!


  • David DelMonte likes this

#14 David DelMonte

David DelMonte

    Forum Master

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

Posted 27 November 2014 - 07:23 AM

Thanks Tarek, very useful...



#15 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 02 December 2014 - 05:51 PM

Tarek,

 

Where can I find that particular sample bundled with all STV 4.0 packages

 

I've added an objection section to a STV 4 table view controller in IB, then added a button to object section. However, I'm having a problem centering the button on table view controller. When I try to center the button in IB, it appears to be centered until I run the app on simulator which displays the button to the far right of view. 

 

Do you have any suggestions?

 

Thanks....



#16 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 03 December 2014 - 05:45 AM

Hi jet21,

 

The sample David is referring to is called "TasksApp-Container".

 

Regarding the centered button, is this a placeholder cell or a regular UIButton inside a cell? We used to have an old text centering bug that got fixed in an earlier release. Are you using our latest STV 4.0.5?



#17 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 03 December 2014 - 01:05 PM

Hi Tarek,

 

It's a placeholder cell. However, I was using STV 4.0.4, wasn't aware of STV 4.0.5. I'll try it with STV 4.0.5 and let you know what happens.

 

Thanks, again..



#18 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 04 December 2014 - 09:22 PM

Tarek,

 

You're right. Button bug appears to have been fixed in STV 4.0.5! :) I have few more questions regarding buttons on SCTableViewController's, though:

 

1.Primarily, I want to add a button to the SCTableViewController's view to link/segue to a specific SCArrayOfObjectsSection. In addition to having the "+" button on the navigation bar, I want to add a button to the SCTableViewController's actual view to accomplish the same purpose as the "+" button on navigation bar. So my question is how do I link a button to a specific SCArrayOfObjectsSection?

 

2. At some point I may want to modify the buttons on the SCTableViewController's navigation bars. For now I've been able to work around it by creating additional SCArrayOfObjectsSections similar to the way you did in the TaskApp (TaskStep).



#19 Dave Guerin

Dave Guerin

    Forum Master

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 541 posts
  • LocationIreland
Reputation: 134
Popular

Posted 05 December 2014 - 04:45 AM

Hi jett21,

 

Assuming you've already added the cell to the tableView, you can use the cell as a + button like this:

 

myCell.cellActions.didSelect = ^(SCTableViewCell *cell, NSIndexPath *indexPath) {
        SCArrayOfItemsSection *section = (SCArrayOfItemsSection*)[cell.ownerTableViewModel sectionAtIndex:0];
        [section dispatchEventAddNewItem];
    };

 

Just change the section index to reflect your table. Note that the cell doesn't have to be in the same section that it's adding new cells to.

 

 

There's also the section property addNewItemCell which will produce an add cell at the bottom of the section.

 

 

 

Adding buttons to the navigation bar is done via the normal self.navigationItem.leftBarButtonItem(s) or self.navigationItem.rightBarButtonItem(s). And in the button action [section dispatchEventAddNewItem] to add, and [section dispatchEventRemoveRowAtIndexPath:indexPath] to remove a cell.


Cheers,

Dave

www.dgapps.ie

#20 jet21

jet21

    Jr. Member

  • STV 4.0 Std
  • PipPip
  • 18 posts
Reputation: 0
Neutral

Posted 05 December 2014 - 04:05 PM

Hi Dave,

 

Thanks for your response. I just want to rephrase part 1 of my initial question to provide more clarity. I added an array of objects to an attribute, then assigned a data definition to the array of objects. All of this was done from within IB STV 4.0.5.

 

When I run the app, I select the option to access the array of objects assigned to the data definition. At that point the view controller provides a "blank" table view - this is where I want to add a button - with a "+" and "edit" button on the navigation bar. If i click on the "+" button it will navigate me to the proper view.

 

However, in order to make the app more user friendly, I want to add a button to the table view just in case the users overlook the '+' button on the navigation bar. 

 

Is this something that can be done from IB (STV 4.0.5) or with myCell.cellActions.didSelect...?

 

Thanks...






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users