0

UISegmentControl のボタンを選択すると、別のビュー コントローラーに 2 つの UITextField 値が渡されます。これらの値は NSMutableDictionary に保存されます。NSMutableDictionary を NSMutableArray に格納します。

私の問題は、2 回目に値を渡し、NSMutableDictionary から前の値を削除すると、最後に渡された値のみが表示されることです。

私が書いたコードは次のとおりです。

-(IBAction)actionOfSaveandSettingSegment:(id)sender
{
    switch ([self.SaveSgCon selectedSegmentIndex])
    {
        case 0:
        {
                UILocalNotification *localNotiStr = [[[UILocalNotification alloc] init] autorelease];
                localNotiStr.fireDate = self.DatePicker.date;
                localNotiStr.alertBody = @"Please Get Up With New Dream...!!!";
                localNotiStr.alertAction=@"View";
                localNotiStr.soundName = UILocalNotificationDefaultSoundName;


               [UIApplication sharedApplication].applicationIconBadgeNumber = [[UIApplication sharedApplication]applicationIconBadgeNumber]+1;
                [[UIApplication sharedApplication] scheduleLocalNotification:localNotiStr];


                SaveAlarmViewController *addView=[[SaveAlarmViewController alloc] init];
                addView.alarmNm=self.alaramName.text;
                addView.alarmTime=self.alaramTime.text;
                addView.notificationsArray=[[UIApplication sharedApplication] scheduledLocalNotifications];
                [self.navigationController pushViewController:addView animated:YES];
                [addView release];

           break;
        }
        default:
            NSLog(@"InValid Selection..!!!");
    }
}

SaveAlarmViewController.h

#import <UIKit/UIKit.h>

@interface SaveAlarmViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
    NSString *alarmNm;
    NSString *alarmTime;

    IBOutlet UITableView *tblAlarmList;
    NSMutableDictionary *AlarmDataDictonry;

    NSArray *notificationsArray;
    NSMutableArray *alramArr;

}

@property(nonatomic,retain)NSMutableArray *alramArr;
@property(nonatomic,retain)NSArray *notificationsArray;
@property(nonatomic,retain)NSString *alarmNm;
@property(nonatomic,retain)NSString *alarmTime;
@property(nonatomic,retain)UITableView *tblAlarmList;
@property(nonatomic,retain)NSMutableDictionary *AlarmDataDictonry;

@end

SaveAlarmViewController.m

- (void)viewDidLoad
{
    self.AlarmDataDictonry=[[NSMutableDictionary alloc] init];
    self.alramArr=[[NSMutableArray alloc] init];
    [self.AlarmDataDictonry setObject:self.alarmNm forKey:@"ALARM_NAME"];
    [self.AlarmDataDictonry setObject:self.alarmTime forKey:@"ALARM_TIME"];    
    [self.alramArr addObject:self.AlarmDataDictonry];

   [super viewDidLoad];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.alramArr count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
            NSString *strRowNo=[NSString stringWithFormat:@"%d )",indexPath.row+1];

            UILabel * rowCount = [[UILabel alloc] initWithFrame:CGRectMake(07,20,25,25)];
            rowCount.text = strRowNo;

            [cell.contentView addSubview:rowCount];
    }


    UILabel * firstNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,20,100,25)];
    firstNameLabel.text = [[self.alramArr objectAtIndex:indexPath.row] objectForKey:@"ALARM_NAME"];

    UILabel * lastNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(50,70, 100, 25)];
    lastNameLabel.text = [[self.alramArr objectAtIndex:indexPath.row] objectForKey:@"ALARM_TIME"];

      [cell.contentView addSubview:firstNameLabel];
    [cell.contentView addSubview:lastNameLabel];

    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
     return cell;
}
4

1 に答える 1

0

がロードされるたびに、辞書が 1 つだけSaveAlarmViewControllerの新しい配列が作成されます。self.alramArrしたがって、テーブル ビューには常に 1 行だけが表示されます。

とは別に配列を保存する必要がありSaveAlarmViewControllerます。次に、項目を配列に追加し、配列全体をビュー コントローラーに渡してテーブルとして表示できます。

于 2012-09-01T14:51:30.157 に答える