簡體   English   中英

如何處理CellForRowAtIndexpath方法

[英]How to Handle CellForRowAtIndexpath method

我有一個表視圖,其中我在一個部分中有15行 所以當表視圖加載時它只顯示前9行 ,我用方法CellForRowAtIndexpath方法檢查它,但是我希望在這個方法中為viewload方法調用所有15行。 請幫幫我。

提前致謝....

這取決於你設置的行數

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

如果你有一個數組然后返回[arr count]; 作為行數,如果你想要靜態行,那么使用return 15; 在這種方法中

您可以使用這些方法,或者如果您希望所有單元格都在第一次查看前面,那么您應該使用最后一個方法減小單元格的高度。還要檢查數組他有多少值。

-(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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM