所以我有一个NSString,我想能够在另一个类访问。在我RootViewController.h我:分配到'只读'返回结果...全球NSString
@interface RootViewController : UITableViewController
+(NSMutableString*)MY_STR;
@property (nonatomic, readwrite, retain) NSString *MY_STR;
@end
在我RootViewController.m:
static NSString* MY_STR;
@synthesize MY_STR;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//The NSDictionary and NSArray items (listOfItems, etc.) are called at top so don't worry about them
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"MovieTitles"];
MY_STR = [array objectAtIndex:indexPath.row];
}
+(NSString*)MY_STR{
return MY_STR;
}
- (void)dealloc {
[MY_STR release];
[super dealloc];
}
现在我NewViewController类我想要写的NSString MY_STR所以在我的.m我有:
#import "RootViewController.h"
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSArray *array = [dictionary objectForKey:@"MovieTitles"];
[RootViewController MY_STR] = [array objectAtIndex:indexPath.row];
}
但在这条线:
[RootViewController MY_STR] = [array objectAtIndex:indexPath.row];
我收到此错误: “分配到一个Objective-C的消息不允许‘只读’返回结果”
任何帮助将是真棒谢谢!
可能的重复[分配给'只读'返回结果不允许,但属性被声明为'读写'](http://stackoverflow.com/questions/10303508/assigning-to-readonly-return-result-not-允许 - 但是财产 - 被宣布 - rea) – Hemang 2014-07-05 10:08:19