代码之家  ›  专栏  ›  技术社区  ›  ewizard

cordova/ios/hybrid应用程序-UITableView加载项目错误且无序

  •  0
  • ewizard  · 技术社区  · 7 年前

    我从我的父母那里得到了奇怪的行为 UITableView 0, 1, 2 3 ,它加载行 4 取而代之,然后是世界其他地区 4. ,它加载行 0 同样,它是这样的:

    表中的行:

    0
    1
    2
    4
    0
    

    很明显应该走了 0, 1, 2, 3, 4 整齐。这是我的密码:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"cellForRowAtIndexPath getting called - row: %li", indexPath.row);
    
        [self.items enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"items at every cell entry: %@", [obj valueForKey:@"item"]);
        }];
    
        //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
        //NSLog(@"indexPath.row: %li, %@", (long)indexPath.row, [self.items objectAtIndex:indexPath.row]);
    
        PoolsTableViewCell *cell = (PoolsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
        if(cell.cellLeftImageView.image == nil) {
    
            NSInteger left = 2*indexPath.row;
            NSLog(@"left: %li", (long)left);
    
            NSObject* obj = (NSObject*)[self.items objectAtIndex:left];
    
            cell.cellLeftViewLabel.text = [obj valueForKey:@"item"];
    
            NSString *ImageURL = [obj valueForKey:@"downloadURL"];
            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
            cell.cellLeftImageView.image = [UIImage imageWithData:imageData];
    
            NSInteger right = (2*indexPath.row)+1;
            NSLog(@"right: %li", (long)right);
    
            if(right < [self.items count]) {
                NSLog(@"inside right < self.items count conditional");
                NSObject* objPlus = (NSObject*)[self.items objectAtIndex:right];
    
                cell.cellRightViewLabel.text = [objPlus valueForKey:@"item"];
    
                NSString *secondImageURL = [objPlus valueForKey:@"downloadURL"];
                NSData *secondImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:secondImageURL]];
                cell.cellRightImageView.image = [UIImage imageWithData:secondImageData];
            }
        }
    
        return cell;
    }
    

    cellForRowAtIndex 称为:

    [self.items enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, 
        BOOL * _Nonnull stop) {
        NSLog(@"items at every cell entry: %@", [obj valueForKey:@"item"]);
    }];
    

    我正在从中加载2个项目 self.items 到每一行(每一行基本上有两列)。控制台输出对于的每个调用都是正确的 cellForRowAtIndexPath -所以呢 自选项目 不应该被无序引用,但它是-这是我的控制台输出的一个例子,当 UITableView

    2019-02-02 22:01:30.121975-0500 HybridPool[1720:534623] cellForRowAtIndexPath getting called - row: 0
    2019-02-02 22:01:30.122149-0500 HybridPool[1720:534623] items at ever cell entry: Table
    2019-02-02 22:01:30.122263-0500 HybridPool[1720:534623] items at ever cell entry: Cord
    2019-02-02 22:01:30.122373-0500 HybridPool[1720:534623] items at ever cell entry: Keys
    2019-02-02 22:01:30.122645-0500 HybridPool[1720:534623] items at ever cell entry: Hshhdhdbd
    2019-02-02 22:01:30.122769-0500 HybridPool[1720:534623] items at ever cell entry: Jhghhvhh
    2019-02-02 22:01:30.122947-0500 HybridPool[1720:534623] items at ever cell entry: Book
    2019-02-02 22:01:30.123054-0500 HybridPool[1720:534623] items at ever cell entry: Njhhnn
    2019-02-02 22:01:30.123160-0500 HybridPool[1720:534623] items at ever cell entry: Tv
    2019-02-02 22:01:30.123260-0500 HybridPool[1720:534623] items at ever cell entry: 9th item
    2019-02-02 22:01:30.129478-0500 HybridPool[1720:534623] left: 0
    2019-02-02 22:01:31.024184-0500 HybridPool[1720:534623] right: 1
    2019-02-02 22:01:31.024302-0500 HybridPool[1720:534623] inside right < self.items count conditional
    2019-02-02 22:01:31.719052-0500 HybridPool[1720:534623] cellForRowAtIndexPath getting called - row: 1
    2019-02-02 22:01:31.719252-0500 HybridPool[1720:534623] items at ever cell entry: Table
    2019-02-02 22:01:31.719374-0500 HybridPool[1720:534623] items at ever cell entry: Cord
    2019-02-02 22:01:31.719481-0500 HybridPool[1720:534623] items at ever cell entry: Keys
    2019-02-02 22:01:31.719584-0500 HybridPool[1720:534623] items at ever cell entry: Hshhdhdbd
    2019-02-02 22:01:31.719687-0500 HybridPool[1720:534623] items at ever cell entry: Jhghhvhh
    2019-02-02 22:01:31.719785-0500 HybridPool[1720:534623] items at ever cell entry: Book
    2019-02-02 22:01:31.719884-0500 HybridPool[1720:534623] items at ever cell entry: Njhhnn
    2019-02-02 22:01:31.720048-0500 HybridPool[1720:534623] items at ever cell entry: Tv
    2019-02-02 22:01:31.720170-0500 HybridPool[1720:534623] items at ever cell entry: 9th item
    2019-02-02 22:01:31.724875-0500 HybridPool[1720:534623] left: 2
    2019-02-02 22:01:32.340747-0500 HybridPool[1720:534623] right: 3
    2019-02-02 22:01:32.340969-0500 HybridPool[1720:534623] inside right < self.items count conditional
    2019-02-02 22:01:32.776360-0500 HybridPool[1720:534623] cellForRowAtIndexPath getting called - row: 2
    2019-02-02 22:01:32.776572-0500 HybridPool[1720:534623] items at ever cell entry: Table
    2019-02-02 22:01:32.776685-0500 HybridPool[1720:534623] items at ever cell entry: Cord
    2019-02-02 22:01:32.776877-0500 HybridPool[1720:534623] items at ever cell entry: Keys
    2019-02-02 22:01:32.777113-0500 HybridPool[1720:534623] items at ever cell entry: Hshhdhdbd
    2019-02-02 22:01:32.777244-0500 HybridPool[1720:534623] items at ever cell entry: Jhghhvhh
    2019-02-02 22:01:32.777344-0500 HybridPool[1720:534623] items at ever cell entry: Book
    2019-02-02 22:01:32.777443-0500 HybridPool[1720:534623] items at ever cell entry: Njhhnn
    2019-02-02 22:01:32.777542-0500 HybridPool[1720:534623] items at ever cell entry: Tv
    2019-02-02 22:01:32.777641-0500 HybridPool[1720:534623] items at ever cell entry: 9th item
    2019-02-02 22:01:32.782148-0500 HybridPool[1720:534623] left: 4
    2019-02-02 22:01:33.383439-0500 HybridPool[1720:534623] right: 5
    2019-02-02 22:01:33.383649-0500 HybridPool[1720:534623] inside right < self.items count conditional
    2019-02-02 22:01:34.534761-0500 HybridPool[1720:534623] cellForRowAtIndexPath getting called - row: 3
    2019-02-02 22:01:34.534980-0500 HybridPool[1720:534623] items at ever cell entry: Table
    2019-02-02 22:01:34.535099-0500 HybridPool[1720:534623] items at ever cell entry: Cord
    2019-02-02 22:01:34.535206-0500 HybridPool[1720:534623] items at ever cell entry: Keys
    2019-02-02 22:01:34.535310-0500 HybridPool[1720:534623] items at ever cell entry: Hshhdhdbd
    2019-02-02 22:01:34.535412-0500 HybridPool[1720:534623] items at ever cell entry: Jhghhvhh
    2019-02-02 22:01:34.535666-0500 HybridPool[1720:534623] items at ever cell entry: Book
    2019-02-02 22:01:34.535787-0500 HybridPool[1720:534623] items at ever cell entry: Njhhnn
    2019-02-02 22:01:34.535895-0500 HybridPool[1720:534623] items at ever cell entry: Tv
    2019-02-02 22:01:34.536022-0500 HybridPool[1720:534623] items at ever cell entry: 9th item
    2019-02-02 22:01:34.540261-0500 HybridPool[1720:534623] left: 6
    2019-02-02 22:01:35.090979-0500 HybridPool[1720:534623] right: 7
    2019-02-02 22:01:35.091111-0500 HybridPool[1720:534623] inside right < self.items count conditional
    2019-02-02 22:01:35.886101-0500 HybridPool[1720:534623] cellForRowAtIndexPath getting called - row: 4
    2019-02-02 22:01:35.886329-0500 HybridPool[1720:534623] items at ever cell entry: Table
    2019-02-02 22:01:35.886446-0500 HybridPool[1720:534623] items at ever cell entry: Cord
    2019-02-02 22:01:35.886554-0500 HybridPool[1720:534623] items at ever cell entry: Keys
    2019-02-02 22:01:35.886658-0500 HybridPool[1720:534623] items at ever cell entry: Hshhdhdbd
    2019-02-02 22:01:35.886978-0500 HybridPool[1720:534623] items at ever cell entry: Jhghhvhh
    2019-02-02 22:01:35.887082-0500 HybridPool[1720:534623] items at ever cell entry: Book
    2019-02-02 22:01:35.887184-0500 HybridPool[1720:534623] items at ever cell entry: Njhhnn
    2019-02-02 22:01:35.887311-0500 HybridPool[1720:534623] items at ever cell entry: Tv
    2019-02-02 22:01:35.887449-0500 HybridPool[1720:534623] items at ever cell entry: 9th item
    2019-02-02 22:01:35.891688-0500 HybridPool[1720:534623] left: 8
    2019-02-02 22:01:36.660758-0500 HybridPool[1720:534623] right: 9
    2019-02-02 22:01:36.931630-0500 HybridPool[1720:534623] Item added! pool
    

    澄清 我在表格中看到的是这样的:

    **Row 0:**
    Table, Cord
    **Row 1:**
    Keys, Hshhdhdbd
    **Row 2:**
    Jhghhvhh, Book
    **Row 3:**
    9th item, (blank - because there are only 9 items - not an even 10) --> this row should be last!
    **Row 4:**
    Table, Cord <- this is the first row again, this should be what is in **Row 3** - 9th item, blank.
    

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
        if([self.items count] % 2 != 0) {
            return ([self.items count] + 1) / 2;
        }
        else {
            return [self.items count] / 2;
        }
    }
    

    对于上面的例子,因为我将两个项目加载到行中,所以我将处理项目数量为偶数的情况(这只是划分) [self.items count] 通过 2 自选项目 ,我补充说 1 除以之前 2.

    Row 0 重复 Row 4

    更新

    得到相同的结果:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"cellForRowAtIndexPath getting called - row: %li", indexPath.row);
    
        [self.leftItems enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"leftItem: %@", [obj valueForKey:@"item"]);
        }];
    
        [self.rightItems enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSLog(@"rightItem: %@", [obj valueForKey:@"item"]);
        }];
    
        //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
        //NSLog(@"indexPath.row: %li, %@", (long)indexPath.row, [self.items objectAtIndex:indexPath.row]);
    
        PoolsTableViewCell *cell = (PoolsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    
        if(cell.cellLeftImageView.image == nil) { //Equivalent to cell == nil
            NSObject* leftObj = [self.leftItems objectAtIndex:indexPath.row];
            NSObject* rightObj = [self.rightItems objectAtIndex:indexPath.row];
    
            cell.cellLeftViewLabel.text = [leftObj valueForKey:@"item"];
    
            NSString *ImageURL = [leftObj valueForKey:@"downloadURL"];
            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
            cell.cellLeftImageView.image = [UIImage imageWithData:imageData];
    
            if(![rightObj isEqual:[NSNull null]]) {
                cell.cellRightViewLabel.text = [rightObj valueForKey:@"item"];
    
                NSString *secondImageURL = [rightObj valueForKey:@"downloadURL"];
                NSData *secondImageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:secondImageURL]];
                cell.cellRightImageView.image = [UIImage imageWithData:secondImageData];
            }
            else {
                cell.cellRightViewLabel.text = @"";
                cell.cellRightImageView.image = nil;
            }
        }
    
        return cell;
    }
    

    2019-02-03 11:32:50.583214-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 0
    2019-02-03 11:32:50.583377-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:32:50.583486-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:32:50.583605-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:32:50.583997-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:32:50.584116-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:32:50.584224-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:32:50.584328-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:32:50.584429-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:32:50.584528-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:32:50.584771-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:32:54.647304-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 1
    2019-02-03 11:32:54.647551-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:32:54.647666-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:32:54.647773-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:32:54.647876-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:32:54.647992-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:32:54.648102-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:32:54.648199-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:32:54.648403-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:32:54.648519-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:32:54.648769-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:32:56.447403-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 2
    2019-02-03 11:32:56.447610-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:32:56.447724-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:32:56.447829-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:32:56.447931-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:32:56.448151-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:32:56.448281-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:32:56.448389-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:32:56.448490-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:32:56.448589-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:32:56.448689-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:32:57.981261-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 3
    2019-02-03 11:32:57.981471-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:32:57.981625-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:32:57.981745-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:32:57.981874-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:32:57.982081-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:32:57.982214-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:32:57.982315-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:32:57.982441-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:32:57.982539-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:32:57.982638-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:33:00.735076-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 4
    2019-02-03 11:33:00.735252-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:33:00.735337-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:33:00.735410-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:33:00.735480-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:33:00.735547-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:33:00.735692-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:33:00.735762-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:33:00.735830-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:33:00.735896-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:33:00.735965-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:33:01.876340-0500 HybridPool[1827:594545] Item added! pool
    2019-02-03 11:33:03.352399-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 3
    2019-02-03 11:33:03.352967-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:33:03.353179-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:33:03.353377-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:33:03.353569-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:33:03.353755-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:33:03.353897-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:33:03.354230-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:33:03.354612-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:33:03.354739-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:33:03.354848-0500 HybridPool[1827:594545] rightItem: <null>
    2019-02-03 11:33:03.477654-0500 HybridPool[1827:594545] cellForRowAtIndexPath getting called - row: 4
    2019-02-03 11:33:03.477863-0500 HybridPool[1827:594545] leftItem: Table
    2019-02-03 11:33:03.477974-0500 HybridPool[1827:594545] leftItem: Keys
    2019-02-03 11:33:03.478078-0500 HybridPool[1827:594545] leftItem: Jhghhvhh
    2019-02-03 11:33:03.478178-0500 HybridPool[1827:594545] leftItem: Njhhnn
    2019-02-03 11:33:03.478276-0500 HybridPool[1827:594545] leftItem: 9th item
    2019-02-03 11:33:03.478374-0500 HybridPool[1827:594545] rightItem: Cord
    2019-02-03 11:33:03.478472-0500 HybridPool[1827:594545] rightItem: Hshhdhdbd
    2019-02-03 11:33:03.478569-0500 HybridPool[1827:594545] rightItem: Book
    2019-02-03 11:33:03.478665-0500 HybridPool[1827:594545] rightItem: Tv
    2019-02-03 11:33:03.478763-0500 HybridPool[1827:594545] rightItem: <null>
    
    2 回复  |  直到 7 年前
        1
  •  1
  •   Jon Rose    7 年前

    tableview中的视图是重用的,因此对视图所做的一切也必须撤消。我的规则是,任何涉及可重用视图的代码都不能有 if else . 也就是说:

    if(cell.cellLeftImageView.image == nil) {
    

    是个虫子。视图第一次将被正确设置,但是第二次,当视图被重用时,它根本不会被设置。

    if(right < [self.items count]) {
    

    也是一个错误。如果没有正确的项目,它不会将图像设置为nil,而是保留以前的图像。

    另外,拥有奇数和偶数表示完全不同的数据源也很难跟踪和理解。你为什么那样做?你可以拥有 leftImageURL rightImageURL , leftText , rightText . 编码的一部分是与其他程序员通信,而不是与编译器通信。选择一个更容易理解的数据结构可以使代码达到预期的效果。

    接下来,您将使用 dataWithContentsOfURL

    valueForKey ? 这是什么类型的 items ? 如果它们是字典,您可以使用item[@“downloadURL”],如果它们是一些自定义对象,您应该可以只使用item.downloadURL。

        2
  •  0
  •   ewizard    7 年前

    leftItems rightItems 是的左栏和右栏 UITableView . 如果给定行的右侧不存在项, [NSNull null] 作为该项的对象传递(从 ):

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        NSLog(@"cellForRowAtIndexPath getting called - row: %li", (long)indexPath.row);
    
        PoolsTableViewCell *cell = (PoolsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"Cell"];
    
        if (cell == nil) {
            NSLog(@"cell == nil");
            cell = [[PoolsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
        }
    
        NSURL* leftURL = [NSURL URLWithString:[[self.leftItems objectAtIndex:indexPath.row] valueForKey:@"downloadURL"]];
        [cell.cellLeftImageView sd_setImageWithURL:leftURL];
        cell.cellLeftViewLabel.text = [[self.leftItems objectAtIndex:indexPath.row] valueForKey:@"item"];
    
        if(![[self.rightItems objectAtIndex:indexPath.row] isEqual:[NSNull null]]) {
            NSURL* rightURL = [NSURL URLWithString:[[self.rightItems objectAtIndex:indexPath.row] valueForKey:@"downloadURL"]];
            [cell.cellRightImageView sd_setImageWithURL:rightURL];
            cell.cellRightViewLabel.text = [[self.rightItems objectAtIndex:indexPath.row] valueForKey:@"item"];
        }
        else {
            cell.cellRightImageView.image = nil;
            cell.cellRightViewLabel.text = @"";
        }
    
        return cell;
    }
    
    ...
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        // Return the number of rows in the section.
        return [self.leftItems count];
    }