0

我想创建一个页面表格视图,并且我想在单击任何单元格时执行特定工作!

(例如,当我单击单元格从特定 URL 地址接收 NSString 值时)

这是我的一段代码:

视图控制器.m

@implementation ViewController
@synthesize tables;

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *Number2 = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:@"http://192.168.1.104/janatan/filemanager.php?dir=root&foldernum"]];
     folderNumber = [Number2 integerValue];

    for (int i=0; i < folderNumber; i++)
    {
        NSString *folderName = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.104/janatan/filemanager.php?dir=root&folder=%d&name",i]]];
        if (!folder)
        {
            folder = [NSMutableArray array];
        }
        [folder addObject:folderName];
    }
    all = [[NSMutableArray alloc]init];
    [all addObjectsFromArray:folder];



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([folder containsObject:[all objectAtIndex:indexPath.row]])
    {
        [self performSegueWithIdentifier:@"segue2" sender:self];
    }
    //I want when to click any cell get NSString from this URL:
    //"http://192.168.1.104/janatan/filemanager.php?dir=root&**folder=%d**&id"
    //(this URL give me id for any folder and any folder is in any cell)
}
4

1 回答 1

0

您可以使用以下代码从 URL 下载字符串

NSURL *url = [NSURL URLWithString:@"your URL to Download String"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *err = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
NSString *responseString = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding];

NSLog(@"Response : %@", responseString);
于 2013-04-17T05:36:46.600 回答