Tôi đã thiết lập đoạn mã sau để lưu một tập tin vào thư mục tài liệu:Liệt kê các tệp đã lưu trong thư mục tài liệu iOS trong UITableView?
NSLog(@"Saving File...");
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.reddexuk.com/logo.png"]];
AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"logo.png"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"Successfully downloaded file to %@", path);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
[operation start];
Tuy nhiên, tôi muốn thêm từng tập tin vào một UITableView khi nó được lưu thành công. Khi tệp trong UITableView được khai thác, tôi muốn một UIWebView điều hướng đến tệp đó (tất cả ngoại tuyến).
Ngoài ra - làm cách nào tôi có thể lấy tên tệp và kết thúc như "logo.png" thay vì http://www.reddexuk.com/logo.png?
Tôi làm cách nào để thực hiện việc này?
cảm ơn, nhưng làm cách nào để đưa dữ liệu này vào UITableView và sau đó mở tệp trong UIWebView? – pixelbitlabs
Đây là hướng dẫn [UITableView] (http://www.iosdevnotes.com/2011/10/uitableview-tutorial/) tốt và đây là liên kết tới [dự án xcode] (https://github.com/cwalcott)/UITableView-Tutorial) cho hướng dẫn này. Đây là một hướng dẫn tốt về [UIWebView] (http://www.iphonesdkarticles.com/2008/08/uiwebview-tutorial.html) – syclonefx
Cảm ơn vì điều đó. Tôi biết làm thế nào để tạo ra một UITableView vv nhưng không chắc chắn làm thế nào để có được các tập tin thực sự vào UITableView chính nó. Trang web bạn đã gửi không thực sự đề cập đến: ( – pixelbitlabs