Welcome, Guest
Username Password: Remember me

Edit Button and SCTableViewModel
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: Edit Button and SCTableViewModel

Edit Button and SCTableViewModel 1 year, 8 months ago #1

I have a view similar to the Apple Contacts app, needs to load in "view only" mode with an Edit button that will allow the fields to be edited when pressed. This view is using an SCObjectSection for all the input cells.

When the view loads, the edit button appears properly but all fields are still editable - not locked. Then when I click the Edit button most of the fields get locked (a few do not).

Any ideas on what I might be doing here? Code for edit button is:
self.navigationItem.rightBarButtonItem = [self editButtonItem];


For those fields that do not lock regardless of edit state I am trying to lock them down in the willConfigureCell delegate method:
- (void)willConfigureCell:(SCTableViewCell *)cell
{
 
if([cell isKindOfClass:[SCDateCell class]])
{
SCDateCell *dateCell = [[SCDateCell alloc] init];
dateCell = (SCDateCell *)cell;
dateCell.allowDetailView = FALSE;
dateCell.datePicker.minuteInterval = 15;
dateCell.label.font = [UIFont fontWithName:@"Helvetica" size:15.0];
dateCell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];
}
 
if([cell isKindOfClass:[SCSelectionCell class]])
{
SCSelectionCell *selCell = [[SCSelectionCell alloc] init];
selCell = (SCSelectionCell *)cell;
// *** What do I need here to lock this field down when not in edit mode? ***
[(SCSelectionCell *)cell label].font = [UIFont fontWithName:@"Helvetica" size:15.0];
[(SCSelectionCell *)cell textLabel].font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];
}
 
if([cell isKindOfClass:[SCTextViewCell class]])
{
[(SCTextViewCell *)cell textView].font = [UIFont fontWithName:@"Helvetica" size:15.0];
[(SCTextViewCell *)cell textLabel].font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];
[(SCTextViewCell *)cell textView].editable = FALSE;
}
 
if([cell isKindOfClass:[SCNumericTextFieldCell class]])
{
SCNumericTextFieldCell *numCell = [[SCNumericTextFieldCell alloc] init];
numCell = (SCNumericTextFieldCell *)cell;
[numCell.textField setEnabled:FALSE];
numCell.textField.font = [UIFont fontWithName:@"Helvetica" size:15.0];
numCell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];
}
 
}


Any help you can provide with this is much appreciated!
  • kes815
  • OFFLINE
  • Junior Boarder
  • Posts: 32
  • Karma: 0

Re: Edit Button and SCTableViewModel 1 year, 8 months ago #2

Hi Karl,

May I please have a look at your class definition code? Thanks!
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Edit Button and SCTableViewModel 1 year, 8 months ago #3

Thanks for sending in your code Karl.

I am not sure that you actually need to use [self editButtonItem] to achieve what you want. When editButtonItem gets tapped, it puts the whole table in "edit mode", where you're able to remove and re-arrange cells. This edit mode prevents cells from being selected (which gives you the impression that selection cells are locked for example) unless you set UITableView allowsSelectionDuringEditing property to TRUE. So in my opinion, you should be using the following code:

 
- (void)viewDidLoad
{
...
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered
target:self action:@selector(editAppt)];
self.navigationItem.rightBarButtonItem = editButton;
[editButton release];
...
}
 
// Now the editAppt implementation should look something like this
- (void)editAppt
{
static BOOL inEditMode = FALSE;
 
// Toggle edit mode
inEditMode = !inEditMode;
 
SCTableViewSection *section = [tableModel sectionAtIndex:1];
for(int i=0; i<section.cellCount; i++)
[section cellAtIndex:i].userInteractionEnabled = inEditMode;
}
 


Hope this helps
  • tarekskr
  • OFFLINE
  • Administrator
  • Posts: 2404
  • Karma: 72

Re: Edit Button and SCTableViewModel 1 year, 8 months ago #4

Thank you - this worked perfectly!
  • kes815
  • OFFLINE
  • Junior Boarder
  • Posts: 32
  • Karma: 0
  • Page:
  • 1
Time to create page: 0.93 seconds