如何将纬度值传递给iphone中的下一个视图?

时间:2012-11-27 06:18:07

标签: ios uitableview navigation

我得到了服务的响应,我有纬度值,我复制到一个数组。 现在我想在单击下一个视图行时传递数组。

我早先通过了地方。在第二个视图UITableViewController中,如果我单击特定行,那么它应该打印行文本值和特定文本的纬度值.....? 这可能......

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

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

这里我打印行的文本,我需要打印每个的纬度值....请帮帮我。

4 个答案:

答案 0 :(得分:5)

将数据从一个视图传递到另一个视图有很多种方法。

最适合你的是:

只需在第二个视图控制器中创建一个变量。

在将值分配给该变量之前,从当前页面推送导航。

现在您可以在第二个视图中轻松使用该值。

答案 1 :(得分:1)

在。SecondViewController .h文件中

@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];

}

我希望这可以帮助你...

答案 2 :(得分:1)

在第二个viewcontroller类@property文件

中创建.h
 @property (nonatomic ) NSString *StrName;
第二个viewcontroller类@synthesize文件中的

.m

@synthesize StrName;

之后在当前的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];

}

答案 3 :(得分:0)

你必须在第二个类中创建一个变量并定义他的属性,在第一个类中你使用这个属性将一个值发送到你喜欢这个值的下一个类

in first class you create a variable with property like this 

@property(非原子,强)NSString * str;

并且在创建第二个类的对象时在第一个类中,然后发送像这样的值

SecondClass *secondClass=[[SecondClass alloc]init];
secondClass.str=@"value is here";

在此方法中,您将值发送到下一个类 我希望你明白; - )