0

これを行う方法はあまりわかりませんが、最初のView Controllerには6つのアイテムの配列があるという考えです。テーブル ビュー セルのいずれかがクリックされると、その特定のセルが削除され、次のコントローラーが残りの 5 つの項目を表示します。

FirstController .m で

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    SecondController *sc = [sb instantiateViewControllerWithIdentifier:@"SecondController"];
    filteredFive = [[NSMutableArray alloc] init];

    // I only display two of it here as it will be very lengthy
    if ([[totalItems objectAtIndex:indexPath.row] isEqual:@"ONE"]) {
        [filteredFive addObject:@"TWO"];
        [filteredFive addObject:@"THREE"];
        [filteredFive addObject:@"FOUR"];
        [filteredFive addObject:@"FIVE"];
        [filteredFive addObject:@"SIX"];
    }

    if ([[totalItems objectAtIndex:indexPath.row] isEqual:@"TWO"]) {
        [filteredFive addObject:@"ONE"];
        [filteredFive addObject:@"THREE"];
        [filteredFive addObject:@"FOUR"];
        [filteredFive addObject:@"FIVE"];
        [filteredFive addObject:@"SIX"];
    }
    [self.navigationController pushViewController:sc animated:NO];
    // this is the part I am trying to transfer the array filteredFive into SecondController's array
    sc.fiveItems = filteredFive;

次に、SecondController.h で

@interface SecondController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
    NSMutableArray *fiveItems;
}
@property (weak, nonatomic) IBOutlet UITableView *secondTable;
@property (nonatomic, retain) NSMutableArray *fiveItems;

@end

SecondController.m

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [fiveItems count];
}

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

    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    cell.textLabel.text = [fiveCourses objectAtIndex:indexPath.row];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

私のコードに、データの表示を禁止するエラーがあるかどうか疑問に思っています。配列をある配列から別の配列に転送できなかったということですか? または、コードが不足しているため、コードが SecondController に表示されませんか?

残りの 5 項目を表示する別の方法があれば、私も試してみたいと思います。

4

0 に答える 0