2011-02-04 41 views
0

我有一个由tableview示例创建的应用程序,并且我设法获取了表中列出的文档目录的文件,看到它是detailview上的内容,现在问题出现在编辑一个文件并且我想保存它时。 当我想要访问RootViewController上的表视图的indexPath.row时,我得到错误:成员'indexPath'的请求不是结构或联合。这是DetaiViewController头:在编译时在某个结构或联合中获取成员'indexPath'的错误请求

#import <UIKit/UIKit.h> 
#import "RootViewController.h" 
@class RootViewController; 

@interface DetailViewController : UIViewController 
{ 
    IBOutlet UITextView *labelName; 
    NSString *strName; 
} 
@property (nonatomic, retain) NSString *strName; 
@property (nonatomic, retain) UITextView *labelName; 

- (IBAction)saveText:(id)sender; 
- (IBAction)hideKeyb:(id)sender; 
@end 

这里是IBOutlet中在遇到麻烦:

- (IBAction)saveText:(id)sender 
{ 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *data = labelName.text; 
    //RootViewController *rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
    RootViewController *rootViewController = [RootViewController alloc] 
    NSString *filename = [NSString stringWithFormat:@"%d.txt",rootViewController.indexPath.row+1]; 
    NSString *wheresave = [documentsDirectory stringByAppendingPathComponent:filename]; 
    NSData *aData = [data dataUsingEncoding:NSUTF8StringEncoding]; 
    [aData writeToFile:wheresave atomically:YES]; 
} 

的错误是在NSString *filename = [NSString stringWithFormat:@"%d.txt",rootViewController.indexPath.row+1];

我想我所有的进口好吧,但我不知道:)提前致谢!

回答

0

我不知道你为什么分配RootViewController,因为它应该已经分配给你说的。

如果您要访问的行(假设这就是选择一个,你可以retrive任何具体的一个,如果你想)在RootViewController的(假设它是从的UITableViewController延伸)应该是这样的:

NSIndexPath *indexPath = [rootViewController.tableView indexPathForSelectedRow];

NSString *filename = [NSString stringWithFormat:@"%d.txt",indexPath.row+1];

+0

好吧设法编译,但它不是保存。我把一个NSLog,它没有显示任何东西:NSLog(indexPath.row); – pmerino 2011-02-04 20:32:59

相关问题