2

以前,我试图使用以下代码转到另一个控制器但失败了

- (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];
}

我正在使用情节提要,所以我发现其他代码对我有用,但我无法为我正在推送的控制器设置标题。

- (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];
}

它工作并显示了 RowDetail 控制器,但我无法编辑标题。知道怎么做吗?

编辑:RowDetail.h

#import <UIKit/UIKit.h>

@interface LecturerDetail : UIViewController

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

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

对于 RowDetail,我尝试使用 IBOutlet 作为导航栏,但失败了。我仍在尝试让标题显示的方法。

4

1 回答 1

1

在 RowDetailViewController 中

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

然后

- (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];
}

然后在视图中确实加载了 RowDetailViewController.m

self.navigationItem.title = rowDetailTitle;

希望对你有帮助,请反馈,谢谢。

更新:或者只是这样做:

- (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];
}
于 2012-11-22T05:01:48.117 回答