我有一个由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];
我想我所有的进口好吧,但我不知道:)提前致谢!
好吧设法编译,但它不是保存。我把一个NSLog,它没有显示任何东西:NSLog(indexPath.row); – pmerino 2011-02-04 20:32:59