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];开发者_StackOverflow中文版
i have want to label1 value fetch another view.i have trid but even not success .if any helped thanks
i have tried such
AppDelegate_iPhone *appDelegate = (AppDelegate_iPhone *)[[UIApplication sharedApplication] delegate];
but value not pass.
Code for CurrentViewControllerHavingTableView
Hi try making a property of your UILabel and synthesize it in the .m file
@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.
Make a Nstring type property in appDeleagate suppose NSString *labelText;
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 . operator.
This will definately help you if you implement in correct way.
精彩评论