【问题标题】:How to Handle CellForRowAtIndexpath method如何处理 CellForRowAtIndexpath 方法
【发布时间】:2012-05-15 21:09:32
【问题描述】:

我有一个表格视图,其中一个部分有 15 行。 所以当表格视图被加载时,它只显示前 9 行,我用 CellForRowAtIndexpath 方法检查了它,但我想在这个方法中调用所有 15 行来调用 viewload 方法。 请帮帮我。

提前谢谢....

【问题讨论】:

  • 你能把你的表格方法贴在这里吗?
  • 问题是你的tableView太小了,不能一次全部显示。要么让你的 tableView 更大,要么让单元格更小。

标签: iphone ipad uitableview


【解决方案1】:

这取决于你设置了多少行

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

如果你有一个数组然后返回 [arr count]; 作为行数,如果您想要静态行,请在此方法中使用 return 15;

【讨论】:

  • 或者他的意思是表格的复用能力没有加载初始的离屏项目。
  • 我认为一个问题必须包含它的代码,以便人们可以轻松理解和回答它
  • @The Saad:我在 numberOfRowsInSection 中尝试了 [arr count],但它仍然在 viewload 上显示 9 行,但是当我滚动表视图时,所有行都会显示。我想在 CellForRowAtIndexpath 方法中调用所有这 15 行,以将每一行 cell.textView 添加到其他数组中。
  • @Wesso 你是对的!我希望表格的重用能力不会加载初始的屏幕外项目。请帮帮我
  • @SanjayDarshil 发布您的代码并在其中提及您想要的内容
【解决方案2】:

您使用这些方法,或者如果您希望所有单元格都位于第一次视图的前面,那么您应该使用最后一个方法降低单元格的高度。同时检查您的数组他有多少值。

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

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

}
-(UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
    cell = [[[UITableViewCell alloc]
             initWithStyle:UITableViewCellStyleSubtitle
             reuseIdentifier:CellIdentifier]
            autorelease];
 }
   cell.textLabel.text=[Array objectAtIndex:indexPath.row];


    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 20;//use this method for cell height
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多