我在讀出可變字典中的可變數組時遇到了問題。我試圖將其讀出來,然後將其放入標籤中。這是我的數據是如何組織的。我有一個可變的字典陣列。然後在我的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
受傷陣列的價值是什麼? –