2012-11-27 20 views
0

我有服務的反應,我有緯度值,我複製到一個數組。 現在我想單擊下一個視圖行時傳遞數組。如何將緯度值傳遞給iPhone中的下一個視圖?

我早些時候通過了地點。在第二個視圖UITableViewController是否有,如果我點擊特定的行,那麼它應該打印行的文本值和特定文本的緯度值.....? 這是可能的...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *myText=[places objectAtIndex:indexPath.row]; 
    NSLog(@"his is selected lattidude value:%@",myText);} 

這裏我打印行的文本與本我需要打印每一個緯度值....請幫助我。

+0

可能的重複[如何將值從一個viewController傳遞給iPhone中的另一個](http://stackoverflow.com/questions/8382063/how-to-pass-value-from-one-viewcontroller-to-another-in-iphone ) – Pfitz

回答

1

在.h文件中的SecondViewController只是

@interface SecondViewController : UIViewController{ 
    NSString *strLatLong; 
} 

@property (nonatomic, retain) NSString *strLatLong; 

@end 

和.m文件只是合成像波紋管..

@synthesize *strLatLong 

,並在您FirstViewController類只是把與婁代碼

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSString *myText=[places objectAtIndex:indexPath.row]; 
    NSLog(@"his is selected lattidude value:%@",myText); 
    SecondViewController *objSecondView = [[SecondViewController alloc]initWithNibName:@"SecondViewController" bundle:nil]; 
    objSecondView.strLatLong = myText; 
    [objSecondView.strLatLong retain]; 
    [self.navigationController pushViewController:objSecondView animated:YES]; 
    [objSecondView release]; 

} 

我希望這可以幫助你...

+0

:隊友來gmail上線 – Vijay

+0

隊友其不要woking? – Vijay

+0

使用此代碼在SecondViewController的viewWillAppear方法中打印此文本,然後檢查其打印文本是否NSLog(@「his is lattidude value:%@」,strLatLong); –

5

有很多種方法可以將數據從一個視圖傳遞到另一個視圖。

最適合你就像是:

在你的第二個視圖控制器只需創建一個變量。

當您在將值分配給該變量之前從當前頁面進行導航時。

現在,您可以在第二個視圖中輕鬆使用該值。

1

排在第二的ViewController類在當前的ViewController類

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    //NSString *myText=[places objectAtIndex:indexPath.row]; 

secondviewcontroller *ss=[[secondviewcontroller alloc]initWithNibName:@"secondviewcontroller" bundle:nil]; 

ss.StrName=[places objectAtIndex:indexPath.row]; 

     [self presentModalViewController:ss animated:YES]; 

} 
0

創建@property.h文件

@property (nonatomic) NSString *StrName; 

排在第二的ViewController類@synthesize.m文件

@synthesize StrName; 

後必須建立在第二類中的變量,然後確定自己的財產,並在第一類中,你使用這個屬性來發送一個值到下一個類你SED值這樣

in first class you create a variable with property like this 

@屬性(非原子,強)的NSString *海峽;

,並在第一類當你創建第二類的對象,那麼你發這樣的

SecondClass *secondClass=[[SecondClass alloc]init]; 
[email protected]"value is here"; 
在這種方法

的價值,你值發送到下一個類 我希望你明白;-)

相關問題