我已经尝试将标签值传递给另一个视图。我已经使用表视图和表视图放置了一个标签。代码......
,例如
- (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];
我想标签1取值另一个视图。我有trid但是甚至没有成功。如果有帮助的话 感谢
我试过了 这样的
AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];
但价值未通过。
答案 0 :(得分: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的对象并通过使用来访问这个属性。操作
如果您以正确的方式实施,这肯定会帮助您。
答案 1 :(得分: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;
这肯定会对你有用。