2012-09-01 3 views
0

UISegmentControl의 단추를 선택하면 다른보기 컨트롤러에서 두 개의 UITextField 값을 전달합니다. 이 값들은 NSMutableDictionary에 저장됩니다. NSMutableArray에 NSMutableDictionary를 저장합니다.UITableViewCell에서 값을 덮어 쓰지 않도록하는 방법은 무엇입니까?

제 문제는 두 번째 값을 전달할 때 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...!!!"; 
       [email protected]"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; 
} 

답변

0

SaveAlarmViewController이로드 될 때마다, 그것은 새로운 배열을 생성 self.alramArr 단 하나의 사전 만 있으면됩니다. 따라서 테이블 뷰에는 항상 하나의 행만 표시됩니다.

배열을 SaveAlarmViewController과 별도로 저장해야합니다. 그런 다음 배열에 항목을 추가하고 전체 배열을 뷰 컨트롤러에 전달하여이를 테이블로 표시 할 수 있습니다.

관련 문제