0

我尝试将标签值传递给另一个视图。我使用表格视图和表格视图放置标签。代码......

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{


 NSString *CellIdentifier = [NSString stringWithFormat:@"%i %i",indexPath.row,indexPath.section];


    UITableViewCell *cell =[self.tableViewdequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
 {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:CellIdentifier] autorelease];

  cell.accessoryType = UITableViewCellAccessoryNone;

  NSMutableArray *arr=[NSMutableArray arrayWithArray:[finalArray objectAtIndex:indexForAll]];
  NSLog(@"-=-=  arr count %d  -=-====",[arr count]);
  NSLog(@"%@",[[arr objectAtIndex:indexPath.row]description]);
   NSLog(@"-======  row  value  %d -=======",indexPath.row);

NSLog(@"--=-=--- strike value %@",[[arr objectAtIndex:indexPath.row]valueForKey:@"Strike"]);

//indexForAll=indexPath.row

cell.accessoryType = UITableViewCellAccessoryNone;

cell.highlighted = YES;

 NSMutableArray *arr2=[NSMutableArray arrayWithArray:[arr objectAtIndex:indexPath.row]];

NSLog(@" -=-=-=-= Arr2 value : %d ",[arr2 count]);

 NSLog(@"%@",[arr2 description]);

//.......................................Strike value.....................................//
  UILabel *label1;
  label1 =[[UILabel alloc]initWithFrame:CGRectMake(10, 3,50, 15)]; 

  NSLog(@"-=-=--= lable1  value  -%@",[[arr2 objectAtIndex:0]valueForKey:@"Strike"]);

[label1 setText:[NSString stringWithFormat:@"%@",
  [[arr2 objectAtIndex:0]valueForKey:@"Strike"]]];

  label1.textAlignment = UITextAlignmentCenter;

  [label1 setFont:[UIFont fontWithName:@"Helvetica" size:12]];

  [label1 setTextColor:[UIColor blackColor]];

  [cell.contentView addSubview:label1];

  NSLog(@"lable1 addded");

  [self.tableView reloadData]; 

我想给 label1 值获取另一个视图。我有过尝试但甚至没有成功。如果有帮助,谢谢

我试过这样

AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];

但价值不及格。

4

2 回答 2

0

在 appDeleagate 中创建一个 Nstring 类型的属性,假设 NSString *labelText;

现在

AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];

In this class where you set this property.

Now before this line

--->[label1 setText:[NSString stringWithFormat:@"%@", [[arr2 objectAtIndex:0]valueForKey:@"Strike"]]];

set that property of appDelegate.
appDelegate.labelText=[NSString stringWithFormat:@"%@", [[arr2 objectAtIndex:0]valueForKey:@"Strike"]];

现在,您要使用此属性的位置创建 appDelegate 对象并使用 . 操作员。

如果您以正确的方式实施,这肯定会对您有所帮助。

于 2010-11-25T10:24:12.187 回答
0

CurrentViewControllerHavingTableView 的代码

您好尝试制作您的 UILabel 的属性并将其合成到 .m 文件中

@property (nonatomic,retain) UILabel *label1;

@synthesize label1;

Now make an object of your current view in the calling class like this


Code for Calling Class

CurrentViewControllerHavingTableView *viewController = [[CurrentViewControllerHavingTableView alloc] initWithNibName:@"CurrentViewControllerHavingTableView" bundle:[NSBundle mainBundle]];

Make a UILabel *label2;

label2.textlabel.text=viewController.label1.textlabel.text;

这肯定会为你工作。

于 2010-11-25T10:24:57.237 回答