我在读出可变字典中的可变数组时遇到了问题。我试图将其读出来,然后将其放入标签中。这是我的数据是如何组织的。我有一个可变的字典阵列。然后在我的tableview中,我将对象放在索引路径中,并将它设置为等于应用程序委托中的字典。然后在细节视图中加载我从数组中取出的字典,然后从中读取并将值放入标签中。我在字典中工作的所有字符串,但数组不会读出来,你能不能帮我如何从NSMutableDictionary中读取NSMutableArray
RootViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SurveyAppAppDelegate *surveyAppAppDelegate = (SurveyAppAppDelegate*)[[UIApplication sharedApplication] delegate];
SurveyViewer *surveyViewController = [[SurveyViewer alloc] initWithNibName:@"SurveyViewer" bundle:nil];
surveyAppAppDelegate.arrayCount = [[self surveyArray] objectAtIndex:indexPath.row];
[self.navigationController pushViewController:surveyViewController animated:YES];
[surveyViewController release];
}
在我的应用程序代表它被设置为NSDictionary的。
然后在我的详细视图控制器我这样做
injuredArray = [surveyAppAppDelegate.arrayCount objectForKey:@"Injured Part"];
if ([injuredArray count] >= 1) {
for (int i = 0; i<=([injuredArray count]-1); i++) {
myLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 105+shift, 139, 15)];
myLabel.text = [injuredArray objectAtIndex:i];
myLabel.backgroundColor = [UIColor clearColor];
myLabel.font = [UIFont fontWithName:@"Helvetica" size: 14.0];
myLabel.textColor = [UIColor blackColor];
myLabel.textAlignment = UITextAlignmentLeft;
[self.theScroller addSubview:myLabel];
shift = shift+20;
}
}
在我的应用程序委托我成立arrayCount这样
.H
#import <UIKit/UIKit.h>
@class RootViewController;
@interface SurveyAppAppDelegate : NSObject <UIApplicationDelegate> {
NSDictionary *arrayCount;
}
@property (nonatomic, assign) NSDictionary *arrayCount;
@end
和.M
#import "SurveyAppAppDelegate.h"
@implementation SurveyAppAppDelegate
@synthesize arrayCount;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
arrayCount = [[NSDictionary alloc] init];
然后在应用程序委托的的dealloc我释放它
哦,并在NSMutableArray中的对象,我设置为injuredArray都是字符串
编辑:因此,我增加一个循环的NSLog在根视图控制器右阵列在我设置它之后,它不工作。所以它看起来出于某种原因,它没有被保存在arrayCount正确
感谢您的帮助
在您的详细视图控制器中,surveyAppAppDelegate的引用来自哪里?你确定它不是空的? – picciano
是的,我将它设置为一个NSDictionary,做属性和综合,然后我初始化它像这样arrayCount = [[NSDictionary alloc] init]; – Nick
受伤阵列的价值是什么? –