objective-c和ios新手在这里,但我正在学习!
name是descs中的字符串。我试图通过detailViewController.note将它传递给新的视图控制器。我可以在调试中看到字符串正在detailViewController.note中保存,但当我转到我的其他视图控制器时,它不在那里。
这是我的表视图控制器中的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
DetailViewController *detailViewController = [[DetailViewController alloc]init];
detailViewController.view.frame=self.view.frame;
detailViewController.title=@"detail";
detailViewController.note=[self.descs[indexPath.row]name];
[[self navigationController] pushViewController:detailViewController animated:YES];
}
DetailViewController的标头:
@interface DetailViewController : UIViewController
@property (nonatomic) NSString * note;
@end
DetailViewController的实现:
- (void)viewDidLoad
{
[super viewDidLoad];
UITextView *description =[[UITextView alloc]initWithFrame:CGRectMake(12,260,300,180)];
description.font=[UIFont fontWithName:@"Helvetica" size:15];
description.editable=NO;
description.text=self.note;
[self.view addSubview:description];
}
提前感谢您的帮助!
答案 0 :(得分:3)
您应该在viewWillAppear:
中设置子视图。它在您当前的实现中不起作用,因为在设置viewDidLoad
之前调用了detailViewController.note
。