【问题标题】:How to pass latitude value to next view in iphone?如何将纬度值传递给iphone中的下一个视图?
【发布时间】:2012-11-27 06:18:06
【问题描述】:

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

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

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

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

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

【问题讨论】:

标签: ios uitableview navigation


【解决方案1】:

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

最适合你的是:

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

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

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

【讨论】:

    【解决方案2】:

    在你的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];
    
    }
    

    希望对你有帮助……

    【讨论】:

    • 使用此代码在 SecondViewController 的 viewWillAppear 方法中打印此文本,然后检查其打印文本与否 NSLog(@"his is selected lattidude value:%@", strLatLong);
    【解决方案3】:

    在第二个视图控制器类.h文件中创建@property

     @property (nonatomic ) NSString *StrName;
    

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

    【讨论】:

      【解决方案4】:

      您必须在第二类中创建一个变量并定义他的属性,并且在第一类中您使用此属性将一个值发送到下一个类中,您像这样 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";
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多