0

首先......如果没有人可以回答这个问题,那没关系......

因为我不知道如何在正确的描述中问这个问题

我的程序是从 URL 获取 plist 数据并将其显示在 iphone tableview 上

我的同事给了我两个 URL 来获取 plist 数据

所以我有两个表视图(tableview1,tableview2

两个 URL(URL1,URL2

我的tableview1通过URL1得到一个plist1,并且tableview1在前 3 行中有 3 个内容

例如(第 0 行 id1),(第 1 行 id2),(第 2 行 id3)

当我选择 row0 时,它将跳转到tableview2并在导航栏上显示标题id1

到目前为止,我能做到...

但在tableview2,它需要一个 URL,如:www.URL2.php?id=1 =>这意味着......

我必须在 URL2 之后添加我的 tableview 标题

获得与 id 1 相关的正确 plist

我的问题是....... URL2是静态的,如何让它像动态一样获得正确的 URL 地址???

嗯.....第一次我以为我的同事会给我一个像数组数组这样的数据

但这不是...我从不尝试使用动态 URL...

这是tableview1中的代码,让我从 URL 获取 plist

 NSURLRequest *theRequest=[NSURLRequest requestWithURL:appDelegate.URL1//I declare the  URL at appDelegate.m for some reasons...
                                                  cachePolicy:NSURLRequestUseProtocolCachePolicy
                                              timeoutInterval:60.0];
      NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest
                           returningResponse:nil error:nil]; 
      NSString *listFile = [[NSString alloc] initWithData:returnData encoding:NSASCIIStringEncoding];   
              self.array = [listFile propertyList];//I parse the data from array to tablecview

这就是我将标题从Tableview1解析到Tableview2的方式

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

    TableView2 *tb2 = [[TableView2 alloc]init];
    tb2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    tb2.title = [[[array objectAtIndex:indexPath.row] valueForKey:@"name"]description];
    [self.navigationController pushViewController:tb2 animated:YES];   }

有任何想法吗 ?

好吧......如果有人能回答这个问题或给我一个方向,我将非常感激

非常感谢所有的回复和回答!!!

哦...还有一件事,我可以使用ASIHTTPRequest发布数据

但我不知道如何在发布后获取数据......?(这有帮助吗?)

4

3 回答 3

1

假设您有一个要附加到 appDelegate.URL1 的字符串,声明为:

NSString *stringToAppend = @"whatever";

然后您可以生成一个包含新 URL 的字符串:

NSString *newURLAsString = [NSString stringWithFormat:@"%@%@",[appDelegate.URL1 absoluteString],stringToAppend];

以及来自该字符串的 NSURL:

NSURL *newURL = [NSURL URLWithString:newURLAsString];

而 NSURLRequest 来自:

NSURLRequest *theRequest=[NSURLRequest requestWithURL:newURL
                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                       timeoutInterval:60.0];
于 2010-11-15T17:51:40.027 回答
1

我不确定你想说什么。

您想从 www.foo.com 加载 tableView1,然后当用户单击一行时,它会定向到另一个 URL,例如 www.foo.com/row0。

最简单的方法是创建一个您在 selectedRow 方法中设置的属性

类似的东西。

在标题中声明属性

@Property (readwrite,copy) NSString* strURL;
于 2010-11-15T18:36:13.237 回答
0



当您想将一些字符串作为参数传递给您的 Api 时, 将字符串附加到 api例如,我存储用户的 lat 和 long,然后将该字符串传递给 API 的 url

NSURL *address1=[NSURL URLWithString:[NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=false",location]];

NSLog(@"your lat and long is::%@",[NSString stringWithFormat:@"http://api.wunderground.com/api/90caafb557ba6bf7/geolookup/conditions/forecast/q/%@.json",location]);

这里 Location 是一个 NSString ,它存储纬度和经度,我将该数据传递给 API 以获取城市、国家和温度等。

在 %@ 的帮助下,我们可以将存储的值传递给 api

于 2014-04-16T09:07:37.797 回答