Helpex - Trao đổi & giúp đỡ Đăng nhập

I wand to know the content of the cell when returning the heightForRowAtIndexPath. In this function how do I get the cell object?

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {


If I try this

 [tableView cellForRowAtIndexPath:indexPath]

it fails and goes off in an infinite loop.

Any idea?

18 hữu ích 0 bình luận 29k xem chia sẻ

Call self (the delegate) rather than the tableView itself.

id cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
26 hữu ích 5 bình luận chia sẻ

Use: func dequeueReusableCellWithIdentifier(identifier: String) -> AnyObject? of UITableView.
Don't use: func dequeueReusableCellWithIdentifier(identifier: String, forIndexPath indexPath: NSIndexPath) -> AnyObject
Possible Reason: heightForRowAtIndexPath gets called before cellForRowAtIndexPath and this method uses the index path to perform additional configuration based on the cell’s position in the table view. But since, there is still no cell yet, hence it goes to infinite loop I think.

2 hữu ích 0 bình luận chia sẻ

The cell hasn't been created when heightForRowAtIndexPath: is called, so there's no way to "get" a cell. Instead, look at your model and determine the height of the cell that way.

If you're concerned about long strings and needing more vertical space in your cell, consider using sizeWithFont:forWidth:lineBreakMode:. Docs here:

1 hữu ích 0 bình luận chia sẻ

I don't think you can or you should. You'll need to determine from indexPath which data you will be displaying in the corresponding cell and thus calculate the needed height of the cell.

So you'll need to write some code to get from indexPath to the right data in your data model.

0 hữu ích 1 bình luận chia sẻ
uitableviewcell *ce=[self.view viewwithtag:indexPath.row]; 

it returns the cell object.

-4 hữu ích 1 bình luận chia sẻ
Không tìm thấy câu trả lời bạn tìm kiếm? Duyệt qua các câu hỏi được gắn thẻ iphone objective-c ios ipad , hoặc hỏi câu hỏi của bạn.

Có thể bạn quan tâm