【发布时间】:2014-07-11 18:42:18
【问题描述】:
我需要在视图之间传递数据。我真的不知道为什么不工作。 SecondViewController 中的变量 selectedRow 始终为空。
FirstViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
SecondViewController *newView = [[SecondViewController alloc] init];
newView.selectedRow = [tablelist objectAtIndex:indexPath.row];
newView.title = [self.tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[self.navigationController pushViewController:newView animated:YES];
}
SecondViewController.h
@interface SecondViewController : UIViewController
{
NSString *title,*selectedRow;
}
@property(nonatomic,retain) NSString *title;
@property (nonatomic,retain) NSString *selectedRow;
@end
SecondViewController.m
@synthesize title,selectedRow;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 64, 320, 370)];
textView.text = selectedRow;
textView.editable = FALSE;
[self.view addSubview:textView.text];
}
return self; }
我挣扎了好几个小时。我真的想不通为什么。 有什么帮助吗? 谢谢
【问题讨论】:
-
确实我遵循了这样的例子。但仍然无法正常工作。我真的不明白为什么。
-
已解决。谢谢你。在 viewDidLoad 方法中移动。
标签: ios objective-c uitableview view controller