您可以尝试 NSUserDefaults 从 textview 存储您的数据,然后将它们读回标签。
编辑:如果您不想使用 NSUserDefaults,因为它不是“正确”的方式(但很简单),您可以试试这个:
在你的 tableViewController.h 中创建一个 NSString:
#import <UIKit/UIKit.h>
@interface TestTableViewController : UITableViewController
@property (nonatomic, strong) NSString *string;
@end
在包含 textView 的 viewController.h 中添加以下内容:
- (IBAction)doneButton;
@property (weak, nonatomic) IBOutlet UITextView *textView;
在 viewController.m 中:
- (IBAction)doneButton {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
TestTableViewController *tvc = (TestTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"TestTableViewController"];
tvc.string = _textView.text;
[tvc setModalPresentationStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:tvc animated:YES];
// ios6 version:
//[self presentViewController:tvc animated:YES completion:nil];}
然后在你的 tableViewController.m 中显示输入数据到你的单元格(你不需要使用标签):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"test";
UITableViewCell *cell = [[UITableViewCell alloc] init];
if (SYSTEM_VERSION_LESS_THAN(@"6.0")) {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; }
else {
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
}
// Configure the cell...
cell.textLabel.text = _string;
return cell;}
不要忘记在你的 tableViewController 的 Storyboard 上将 Storyboard ID 设置为身份检查器!!