2

Previously, I was trying to go to another controller using the following code but failed

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    RowDetail *rd = [[RowDetail alloc]initWithNibName:@"RowDetail" bundle:nil];
    if ([[allRow objectAtIndex:indexPath.row] is Equal:@"One"]) 
    {
        [rd setTitle:[allRow objectAtIndex:indexPath.row]];
    }
    [self.navigationalController pushViewController:rd animated:NO];
}

I am using a storyboard so I found the other code worked for me but I could not set the title for the controller I was pushing.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
    RowDetail *rd = [sb instantiateViewControllerWithIdentifier:@"RowDetail"];
    if ([[allRow objectAtIndex:indexPath.row] is Equal:@"One"]) 
    {
        [rd setTitle:[allRow objectAtIndex:indexPath.row]];
    }
    [self.navigationalController pushViewController:rd animated:NO];
}

It worked and showed the RowDetail controller but I could not edit the title. Any idea how can this be done?

EDIT: RowDetail.h

#import <UIKit/UIKit.h>

@interface LecturerDetail : UIViewController

@property (weak, nonatomic) IBOutlet UINavigationBar *rowNavBar;

@property (nonatomic, strong) NSString *lecDetailTitle;
@end

For the RowDetail, I tried using IBOutlet for the navigation bar but failed. I am still trying ways to let the title to show.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jlim
  • 23
  • 4

1 Answers1

1

In RowDetailViewController

@property (nonatomic, strong) NSString *rowDetailTitle;
//synthesize in .m file too

then

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
    RowDetail *rd = [sb instantiateViewControllerWithIdentifier:@"RowDetail"];
    rd.rowDetailTitle = @"yourTitle";
    [self.navigationalController pushViewController:rd animated:NO];
}

then in view did load of RowDetailViewController.m

self.navigationItem.title = rowDetailTitle;

hope it help, please give a feedback, thanks.

UPDATE: or just simply do this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryBoard" bundle:nil];
    RowDetail *rd = [sb instantiateViewControllerWithIdentifier:@"RowDetail"];
    rd.navigationItem.title = @"yourTitle";
    [self.navigationalController pushViewController:rd animated:NO];
}
piam
  • 653
  • 6
  • 13
  • I tried both method but it still doesn't show the title screen – Jlim Nov 22 '12 at 06:20
  • can I see your RowDetailViewController.h ? – piam Nov 22 '12 at 06:29
  • rowNavBar.title = self.navigationItem.title; in viewdidload of RowDetailViewController.m – piam Nov 22 '12 at 06:46
  • rowNavBar.topItem.title = self.navigationalItem.title; – Jlim Nov 22 '12 at 06:57
  • I misreading your .h file , so for conclusion UINavigationBar use navBar.topItem.title = @"title"; but if UINavigationItem do as I said :) – piam Nov 22 '12 at 07:08
  • Another question, if I want to do the same method for button instead of navigational title, how do I go about doing it? – Jlim Nov 22 '12 at 08:27
  • you mean something like this – piam Nov 22 '12 at 08:52
  • Nope, I mean for a rounded rect button. There is a rounded rect button in the RowDetailViewController and I want to edit it in the previous controller. – Jlim Nov 22 '12 at 08:56
  • For your second question, after I tried, unfortunately it failed :(, why don't you edit your button in RowDetailViewController.m? sorry dude. – piam Nov 22 '12 at 09:54
  • I'll need to use my array in the previous controller to vary the output in RowDetailViewController that's why. I will try figure. – Jlim Nov 22 '12 at 10:13
  • so the only solution that I can think is to send value from previous controller to RowDetailViewController look at my first answer, you have to do like that then edit you roundrecBtn according to the value you have sent in viewdidload – piam Nov 22 '12 at 10:18