Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何防止覆盖UITableViewCell中的值?_Iphone_Objective C_Ios_Uitableview - Fatal编程技术网

Iphone 如何防止覆盖UITableViewCell中的值?

Iphone 如何防止覆盖UITableViewCell中的值?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,当我选择UISegmentControl的按钮时,我会在另一个视图控制器上传递两个UITextField值。这些值存储在NSMutableDictionary中。我将NSMutableDictionary存储在NSMutableArray中 我的问题是,当我第二次传递值,然后从NSMutableDictionary中删除以前的值时,只显示作为上次传递的值 以下是我编写的代码: -(IBAction)actionOfSaveandSettingSegment:(id)sender { sw

当我选择UISegmentControl的按钮时,我会在另一个视图控制器上传递两个UITextField值。这些值存储在NSMutableDictionary中。我将NSMutableDictionary存储在NSMutableArray中

我的问题是,当我第二次传递值,然后从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
时,它只使用一个字典创建一个新数组
self.alramArr
。因此,表视图将始终只显示一行

您应该将阵列与
SaveAlarmViewController
分开存储。然后,您可以向数组中添加一个项,并将整个数组传递给视图控制器以将其显示为表

- (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;
}