0

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

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

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

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

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

4

4 回答 4

5

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

最适合你的是:

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

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

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

于 2012-11-27T06:25:30.117 回答
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];

}

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

于 2012-11-27T06:33:46.763 回答
1

@property在第二个 viewcontroller 类.h文件中创建

 @property (nonatomic ) NSString *StrName;

@synthesize在第二个视图控制器类.m文件中

@synthesize StrName;

之后在您当前的视图控制器类中

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

}
于 2012-11-27T06:33:58.590 回答
0

您必须在第二类中创建一个变量并定义他的属性,在第一类中您使用此属性将一个值发送到下一个类您像这样 sed 值

in first class you create a variable with property like this 

@property(nonatomic ,strong) NSString *str;

在第一类中,当您创建第二类的对象时,您会像这样发送值

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

在这种方法中,您将价值发送到下一堂我希望您理解 ;-)

于 2012-11-27T06:34:12.620 回答