1

我在段控件中有两个数组和三个按钮

  -(void)viewDidLoad{ 
  if(!resultArray){

    resultArray =[[NSMutableArray alloc] init];
}

   [self setUpData];

   if(!nextArray){

    nextArray =[[NSMutableArray alloc] init];
 }

    [self nextData];
   appointmentsOfDay = [[NSMutableArray alloc] arrayWithArray:resultArray copyItems:YES];
    }


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

 return [appointmentsOfDay count];



}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UILabel * dobLabel = nil;
static NSString * Identifier = @"Identifier";
UITableViewCell * cell = [table dequeueReusableCellWithIdentifier:Identifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier] autorelease];

    dobLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 6, 100, 32)];
    dobLabel.font = [UIFont systemFontOfSize:15];
    dobLabel.tag = 999;
    [cell addSubview:dobLabel];
    [dobLabel release];
 }
 else {
     dobLabel = (UILabel *)[cell viewWithTag:999];
 }

appDelegate = (EMRAppDelegate *)[[UIApplication sharedApplication] delegate];

 ObjectData *theCellData = [appointmentOfDay objectAtIndex:indexPath.row];





     cell.textLabel.font = [UIFont systemFontOfSize:15];
     cell.textLabel.textAlignment = UITextAlignmentLeft;
     cell.textLabel.text=[NSString stringWithFormat:@"%@ %@",theCellData.firstName,theCellData.lasttName];

    dobLabel.text = theCellData.appointmentTime;





      return cell;
    }


  - (void)onDayButtonClick:(id)sender
  {
     UISegmentedControl * segmentedControl = (UISegmentedControl *)sender;


   [appointmentsOfDay removeAllObjects];
    if (segmentedControl.selectedSegmentIndex == 0) {


        [appointmentsOfDay removeAllObjects];


         appointmentsOfDay = [[NSMutableArray alloc] arrayWithArray:resultArray copyItems:YES];



    }

    else if (segmentedControl.selectedSegmentIndex == 1) {

        [appointmentsOfDay addObject:nextArray];


    }
    else if (segmentedControl.selectedSegmentIndex == 2) {

    }

[table reloadData];
}

崩溃报告

 EMR[1161:10703] -[__NSPlaceholderArray arrayWithArray:copyItems:]: unrecognized selector sent to instance 0x7320120
2012-04-09 14:13:35.021 EMR[1161:10703] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSPlaceholderArray arrayWithArray:copyItems:]: unrecognized selector sent to instance 0x7320120'
 *** First throw call stack:
 (0x201d052 0x2d01d0a 0x201eced 0x1f83f00 0x1f83ce2 0xc7a7 0x6bc64e 0x6bc941 0x6ce47d  0x6ce66f 0x6ce93b 0x6cf3df 0x6cf986 0x6cf5a4 0x9660 0x201eec9 0x5f95c2 0x5f955a 0x69eb76 0x69f03f 0x69e2fe 0x61ea30 0x61ec56 0x605384 0x5f8aa9 0x2f72fa9 0x1ff11c5 0x1f56022 0x1f5490a 0x1f53db4 0x1f53ccb 0x2f71879 0x2f7193e 0x5f6a9b 0x25bd 0x2535)
terminate called throwing an exception(lldb) 
4

3 回答 3

0

问题是你appointmentsOfDay每次都在分配,所以删除下面的代码,

 appointmentsOfDay = [[NSMutableArray alloc] arrayWithArray:resultArray copyItems:YES];

并将其添加到 viewdidload。

然后,

if (segmentedControl.selectedSegmentIndex == 0) {

        [appointmentsOfDay addObject:resultArray];

    }

else if (segmentedControl.selectedSegmentIndex == 1) {

        [appointmentsOfDay addObject:nextArray];

    }
于 2012-04-09T08:54:37.753 回答
0

以下代码正在实施,可能会解决您的问题

在此我在按下按钮时实现了两个数组,然后另一个数组填充到 Uitable 中。

鉴于 load 方法是否实现了以下代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.arOne=[NSArray arrayWithObjects:@"1",@"a",@"b",@"c",@"d",@"e", nil];
    self.arTwo=[NSArray arrayWithObjects:@"x",@"y",@"z",@"o",@"p", nil];
    [self.tableView reloadData];
}

在 cellForRowAtIndexPath 方法中实现以下代码

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

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text=[(self.btnTapped.selected)?self.arTwo:self.arOne objectAtIndex:indexPath.row];

    return cell;
}

控制与方法之间连接的IBAction方法

- (IBAction)btnTitle:(id)sender {
    self.btnTapped.selected=!self.btnTapped.selected;
    [self.tableView reloadData];
}

愿这有助于解决您的问题

于 2012-04-09T08:56:35.787 回答
0

这是我更喜欢使用的方法。参考您的分段控件。声明一个只读属性

@property (nonatomic, readonly) NSArray *appointmentOfDay;

并将其实现为

-(NSArray*) appointmentOfDay {
    NSArray *tData;
    if (self.segmentedControl.value==0) {
        //instantiate tData based on value
    }
    // do for all segmented control value
    return tData;
}

reloadData并在单击 Day 按钮时调用。

于 2012-04-09T08:58:13.727 回答