在我的申请中,我将在最初UITableView只显示一行。我想增加的行为用户加载上一行与数据(UIImage的,在这里)。由于现在我返回值1,在numberOfRowsInSection:方法,因为我不知道如何实现它所要求的方式。请帮助。

cellForRowAtIndexPath:方法是

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

     CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CustomCellIdentifier];
     if (cell == nil) {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CustomCellIdentifier ] autorelease];

         NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];      
         for (id currentObject in nib){
             if ([currentObject isKindOfClass:[CustomCell class]]){
                 cell = (CustomCell *)currentObject;
                 cell.viewController = self;
                 break;
             }
         }          
     }
     if (j<15){
                 cell.imageView.image = nil;
         if (count!=0)
         {
             @try{
                NSInteger row = [indexPath row];
                 cell.imageView.image = [array objectAtIndex:row];
                  }
             @catch (NSException* ex) {
                 NSLog(@"doSomethingFancy failed: %@",ex);
             }
         }
     }
     cell.showsReorderControl = YES;
      return cell;
     [array release];
 }

,如果条件和计数是什么,但只是用于检查可变数组的正确功能,“阵列”。

有帮助吗?

解决方案

您应该阅读本文档: HTTP ://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/Introduction/Introduction.html

,看一下相关样品以及

请注意:在你的代码[阵列发行]将不会被调用,因为你刚刚才得到了一个return语句

其他提示

当到达在某一cellForRowAtIndexPathindexPath,这意味着正在显示的行。如果到达最后一排,你可以插入新行到表中。要做到这一点,你只需要增加将由tableView:numberOfRowsInSection功能得到恢复计数。

我猜你的numberOfRowsInSection功能看起来是这样的:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return section==0 ? [array count] : 0;
}

因此,基本上,内部的cellForRowAtIndexPath,添加以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     ...

     if([indexPath row]==[array count]-1) {
         [array addObject:(NEXT_IMAGE)];
     }
     return cell;
 }

您还需要刷新表。一种方法是只是调用reloadData在你的UITableView,但最好的方法是调用beginUpdates / insertRowsAtIndexPaths / endUpdates在桌子上,这样就可以显示正在插入的行的一个漂亮的动画。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top