我正在使用 IOS 5 和 Storyboard 编码。我已经构建了一个应用程序,其中我有一个 tableView 连接到一个带有搜索栏的 sqlite 数据库。当我们触摸一行时,它会自动将我们带到另一个名为“Details”的视图控制器。我需要将数据从我的表格视图传递到详细信息视图控制器,例如将 author.title 传递给 labelText.text 字段。有任何想法吗?
编辑问题:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
// NSString *Title;
Details *dv = (Details*)segue.destinationViewController;
author.title = dv.labelText.text;
}
部分代码:
//
// Details.m
// AuthorsApp
//
// Created by georges ouyoun on 7/17/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "Details.h"
#import "Author.h"
@interface Details ()
@end
@implementation Details
@synthesize labelText;
@synthesize selectedAuthors;
@synthesize author;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.labelText.text = self.author.title;
// Do any additional setup after loading the view.
NSLog(@"Everything is ok now !");
}
- (void)viewDidUnload
{
// [self setLabelText:nil];
NSLog(@"U have entered view did unload");
[super viewDidUnload];
[self setLabelText:Nil];
// Release any retained subviews of the main view.
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
// NSString *Title;
Details *dv = (Details*)segue.destinationViewController;
// author.title = dv.labelText.text;
dv.labelText.text = author.title;
}
/*
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"AuthorsCell"]) {
[segue.destinationViewController setLabelText:author.title];
}
}
/*
-(void)viewWillAppear:(BOOL)animated
{
self.labelText.text = author.title;
NSLog(@"U have entered the viewWillAppear tag");
// detailsLabel.text = food.description;
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)dealloc {
[labelText release];
[super dealloc];
}
@end