2012-03-29 152 views
1

如何在iPhone中的應用程序中點擊按鈕時打開文件瀏覽器,它必須顯示擴展名爲.pdf格式的文件。必須保存到本地數據庫。例如,如果我們想發送電子郵件到xyz,我們附加一些文件,如果我們想發送文件。如果我們點擊附加文件按鈕,它會顯示文件資源管理器。在如果用戶點擊iphone中的按鈕,文件資源管理器也必須打開。請幫助我解決這個問題。如何打開文件瀏覽器並在ios中選擇一個.pdf文件

回答

1

我做了類似於我的IOS應用程序的東西。由於IOS沒有(我認爲)一個文件瀏覽器,並且你在大熱的時候只允許在他點擊附加文件時使用你的應用程序的Documents文件夾,所以我打開一個UIPopoverController,然後向他展示帶有擴展名I的所有文件想。在我的情況是該.csv文件,我用這個算法:

 _data= [[NSMutableArray alloc] init]; 
    NSString *documentsPath= [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
    NSError *error; 
    NSArray* files= [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error]; 
    NSRange range; 

    for (NSString* file in files) { 
     range = [file rangeOfString:@".csv" 
          options:NSCaseInsensitiveSearch]; 
     if (range.location!= NSNotFound) { 
      [_data addObject:file]; 
     } 
    } 

凡_data是一個數組,我在的tableView使用知道所有的CSV文件,我有。如果您想在文件瀏覽器中顯示目錄,並讓用戶遞歸地將文件看到目錄中,則可以這樣做。我的表數據源:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [_data count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

if (cell==nil) { 
    cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
}  
cell.textLabel.text=[_data objectAtIndex:indexPath.row];  
return cell; 
} 

我希望它能幫助你

相關問題