获取成员“indexPath”的错误请求编译时不是结构或联合的东西
我有一个由表格视图示例制作的应用程序,我设法获取表格上列出的文档目录的文件,并且还获得了在详细视图上查看其内容的方法,现在当我编辑一个文件并且我想要时出现问题保存它。 当我想访问 RootViewController 上的表视图的 indexPath.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
这是我遇到麻烦的 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 ];
我想我已经完成了所有导入,但我不确定:) 提前致谢!
I have an app made from tableview example, and I managed to get the files of documents directory listed on the table, and also got the way for seeing it's content on the detailview, now the problem comes when I edited one file and I want to save it.
I get the error: request for member 'indexPath' in something not a structure or union when I want to access indexPath.row of the table view which is on RootViewController. This is the header for 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
And here is the IBOutlet in where I'm having trouble:
- (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];
}
The error is at NSString *filename = [NSString stringWithFormat:@"%d.txt",rootViewController.indexPath.row+1];
I think I have all the imports ok, but i'm not sure :) Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道为什么你要分配 RootViewController 因为它应该已经分配给你所说的。
如果你想访问 RootViewController 中的一行(假设这是选定的一行,如果你愿意的话,你可以检索任何特定的一行)(假设它是从 UITableViewController 扩展的),它应该是这样的:
I'm not sure why you're allocating RootViewController since it should be already allocated for what you're saying.
If you want to access a row (let's say that's the selected one, you can retrive any specific one if you want) in the RootViewController (assuming it's extending from UITableViewController) it should be something like this: