-1

我需要将所选表格视图行的 UiLabel 值传递给其他视图中的标签。我该怎么做?我试过这个:

 ViewController1.h:
UILabel *name1;
@property(nonatomic,retain)IBOutlet UILabel *name1;

    ViewController1.m:
- (void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{

ViewController2 *v2 = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
v2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

[self presentModalViewController:v2 animated:YES];
 v2.provName=[name1 retain];   //name1 is the name of UILabel in TableView.
[v2 release];
}
    ViewController2.h
UILabel *providerName;
SString *provName;

    ViewController2.m:
- (void)viewDidLoad
{
providerName =[[UILabel alloc] init];
[providerName setFrame:CGRectMake(10,10,300,50) ];
providerName.textAlignment=UITextAlignmentLeft;
providerName.backgroundColor=[UIColor blackColor];

self.providerName.text=self.provName; 
 providerName.highlightedTextColor=[UIColor whiteColor];
[self.view addSubview:providerName];
}

但没有得到价值

4

2 回答 2

0

如果provName是字符串,则为其分配标签文本的值,而不是标签本身。

于 2012-10-09T12:15:37.763 回答
0

您应该在第二个视图控制器中更新标签的文本:

v2.providerName.text = name1.text;

或者,更好的是,将名称封装在您在第一个视图控制器中执行此操作的第二个视图控制器中:

v2.provName = name1.text;

并在第二个视图控制器中提供一个设置器:

- (void)setProvName:(NSString *)name
{
    // This assumes that ARC is enable - if it isn't then you have to retain...

    self.provName = name;
    self.providerName.text = name;
}
于 2012-10-09T12:22:08.773 回答