UA-17470720-3

Jump to content


Photo
- - - - -

how to add custom button on navigation bar? and the delegate method is not working

general actions sections models

  • Please log in to reply
5 replies to this topic

#1 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 21 February 2013 - 08:44 AM

Hi,

I am trying to add custom BarButtonItem on my detailview's navigation bar. but the bar button item is not showing, also the tablemodel's delegate(- (void)tableViewModel:(SCTableViewModel *)tableModel
detailViewWillDismissForRowAtIndexPath:(NSIndexPath *)indexPath) method also not firing.


SCClassDefinition *taskDef = [SCClassDefinition definitionWithClass:[Task class]

propertyNamesString:@"taskText;description;dueDate"];

SCPropertyDefinition *descPropertyDef = [taskDef propertyDefinitionWithName:@"description"];

descPropertyDef.type = SCPropertyTypeTextView;

SCObjectSection *section = [SCObjectSection sectionWithHeaderTitle:nil boundObject:task boundObjectDefinition:taskDef];

[self.tableViewModel addSection:section];

self.tableViewModel.delegate=self;


[self.navigationController.navigationItem setLeftBarButtonItem:nil];


UIBarButtonItem *rightbtn = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addButtonclicked)];


[self.navigationController.navigationItem setRightBarButtonItem:rightbtn];



Thanks,

bala


#2 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 21 February 2013 - 07:50 PM

any help?

#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 22 February 2013 - 11:00 AM

Hi bala,

You should use self.navigationItem instead of self.navigationController.navigationItem.

the tablemodel's delegate(- (void)tableViewModel:(SCTableViewModel *)tableModel
detailViewWillDismissForRowAtIndexPath:(NSIndexPath *)indexPath) method also not firing.


Please try not to use delegates as they've been deprecated for being too complicated to work with (they're included only for backward compatibility with the old STV 2.0). The recommended way is to use the much more popular "actions" feature instead. In your case, you should be using the sectionActions.detailViewWillDismiss action. For more information, please refer to our eBook chapter titled "Actions".
  • cometlinear likes this

#4 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 23 February 2013 - 01:06 AM

Hi Tarek,

Still I am not getting the button which i included in the code.


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

SCClassDefinition *taskDef = [SCClassDefinition definitionWithClass:[Task class]
propertyNamesString:@"taskText;description;dueDate"];
SCPropertyDefinition *descPropertyDef = [taskDef propertyDefinitionWithName:@"description"];
descPropertyDef.type = SCPropertyTypeTextView;
SCObjectSection *section = [SCObjectSection sectionWithHeaderTitle:nil boundObject:task boundObjectDefinition:taskDef];
[self.tableViewModel addSection:section];
self.tableViewModel.delegate=self;
[self.navigationItem setLeftBarButtonItem:nil];

UIBarButtonItem *rightbtn = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addButtonclicked)];
[self.navigationItem setRightBarButtonItem:rightbtn];
}

Thanks,
bala.

Edited by Balachandhar, 23 February 2013 - 01:12 AM.


#5 Balachandhar

Balachandhar

    Experienced Member

  • STV 3.0 Pro
  • PipPipPipPip
  • 87 posts
Reputation: 21
Excellent

Posted 23 February 2013 - 09:55 AM

is it a bug in STV?

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 25 February 2013 - 03:00 PM

Hi Bala,

This is not a bug in STV. When I paste your added lines in -viewDidLoad of TasksViewController.m (Core Data App sample), it works as it should by displaying an "Add" button to the right. Here is the code I pasted:


    [self.navigationItem setLeftBarButtonItem:nil];

    UIBarButtonItem *rightbtn = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStyleDone target:self action:@selector(addButtonclicked)];
    [self.navigationItem setRightBarButtonItem:rightbtn];






Also tagged with one or more of these keywords: general, actions, sections, models

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users