Iphone 编译时获取非结构或联合中成员“indexPath”的错误请求

Iphone 编译时获取非结构或联合中成员“indexPath”的错误请求,iphone,objective-c,uitableview,nsstring,ipod,Iphone,Objective C,Uitableview,Nsstring,Ipod,我有一个从tableview示例制作的应用程序,我设法获得了表上列出的documents目录文件,还获得了在detailview上查看其内容的方法,现在问题来了,当我编辑一个文件并想要保存它时。 我得到了一个错误:当我想要访问RootViewController上的表视图的indexath.row时,请求非结构或联合中的成员'indexPath'。这是DetaiViewController的标题: #import <UIKit/UIKit.h> #import "RootViewCo

我有一个从tableview示例制作的应用程序,我设法获得了表上列出的documents目录文件,还获得了在detailview上查看其内容的方法,现在问题来了,当我编辑一个文件并想要保存它时。 我得到了一个错误:当我想要访问RootViewController上的表视图的indexath.row时,请求非结构或联合中的成员'indexPath'。这是DetaiViewController的标题:

#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
错误位于NSString*文件名=[NSString stringWithFormat:@%d.txt,rootViewController.indexPath.row+1]


我想我所有的进口产品都可以,但我不确定:提前谢谢

我不确定您为什么要分配RootViewController,因为它应该已经分配给您所说的内容

如果要访问某一行(假设该行是所选行),则可以在RootViewController中检索任何特定行(如果需要),前提是该行是从UITableViewController扩展而来的,它应该是这样的:

nsindepath*indepath= [rootViewController.tableView indexPathForSelectedRow]

NSString *文件名=[NSString stringWithFormat:@%d.txt,indexath.row+1]


好的,我设法编译了,但没有保存。我放置了一个NSLog,它没有显示任何内容:nslogindepath.row;
- (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];
}