[英]how to use application delegate method in iphone
i have try the label value pass one view to another view .i have use the table view and table view put a label . 我尝试将标签值传递给另一个视图。我使用表视图和表视图放置标签。 code...... 码......
such as 如
- (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];
i have want to label1 value fetch another view.i have trid but even not success .if any helped thanks 我想给label1值获取另一个视图。我尝试过但没有成功。如果有帮助,谢谢
i have tried such 我已经尝试过
AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];
but value not pass. 但价值不及格。
Make a Nstring type property in appDeleagate suppose NSString *labelText; 假设NSString * labelText;在appDeleagate中创建一个Nstring类型的属性。
and now 现在
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"]];
And now where you want to use this property make object of appDelegate and access this property by using . 现在,您要在其中使用此属性的地方创建appDelegate的对象,并使用来访问此属性。 operator. 操作员。
This will definately help you if you implement in correct way. 如果您以正确的方式实施,这绝对会为您提供帮助。
Code for CurrentViewControllerHavingTableView CurrentViewControllerHavingTableView的代码
Hi try making a property of your UILabel and synthesize it in the .m file 嗨,尝试制作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;
This will surely work for you. 这肯定会为您工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.