Xcode13 iOS15 tableView cellForRowAtIndexPath: return a different cell - uitableview

In Xcode13 iOS15, every time I call [tableView reloadData]; cellForRowAtIndexPath always return a different cell, it makes my app very strange... So I wrote a Demo to verify this.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 300;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"identifier"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"identifier"];
}
if (indexPath.row & 1) {
cell.backgroundColor = [UIColor blueColor];
} else {
cell.backgroundColor = [UIColor redColor];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"%# %#", [self.tableView cellForRowAtIndexPath:indexPath], indexPath);
[self.tableView reloadData];
}
When I test my code in iOS15
2021-10-22 19:17:20.165792+0800 JQIApp[7636:1158455] <UITableViewCell: 0x7fa25770c670; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x6000032c0240>> <NSIndexPath: 0xe668878fbccf53cf> {length = 2, path = 0 - 0}
2021-10-22 19:17:20.343009+0800 JQIApp[7636:1158455] <UITableViewCell: 0x7fa25a009350; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x6000032fb380>> <NSIndexPath: 0xe668878fbccf53cf> {length = 2, path = 0 - 0}
2021-10-22 19:17:20.548892+0800 JQIApp[7636:1158455] <UITableViewCell: 0x7fa25a0053b0; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x6000032fb160>> <NSIndexPath: 0xe668878fbccf53cf> {length = 2, path = 0 - 0}
2021-10-22 19:17:20.712690+0800 JQIApp[7636:1158455] <UITableViewCell: 0x7fa25770c670; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x6000032c0240>> <NSIndexPath: 0xe668878fbccf53cf> {length = 2, path = 0 - 0}
When I test my code in iOS14
2021-10-22 19:18:43.014213+0800 JQIApp[8053:1170522] <UITableViewCell: 0x7f8a08817200; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x60000258d660>> <NSIndexPath: 0xe365b32ef41b1634> {length = 2, path = 0 - 0}
2021-10-22 19:18:43.409228+0800 JQIApp[8053:1170522] <UITableViewCell: 0x7f8a08817200; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x60000258d660>> <NSIndexPath: 0xe365b32ef41b1634> {length = 2, path = 0 - 0}
2021-10-22 19:18:43.834151+0800 JQIApp[8053:1170522] <UITableViewCell: 0x7f8a08817200; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x60000258d660>> <NSIndexPath: 0xe365b32ef41b1634> {length = 2, path = 0 - 0}
2021-10-22 19:18:44.410295+0800 JQIApp[8053:1170522] <UITableViewCell: 0x7f8a08817200; frame = (0 0; 375 300); autoresize = W; layer = <CALayer: 0x60000258d660>> <NSIndexPath: 0xe365b32ef41b1634> {length = 2, path = 0 - 0}
Does anyone know what has changed on iOS15 and how to resolve it?

You can resolve this by passing different identifier for each cell. Checkout https://developer.apple.com/videos/play/wwdc2021/10252/
NSString *identifier = [NSString stringWithFormat:#"cell_identifer_%ld_%ld", indexPath.section, indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"identifier"];

Related

TableViewCellContentView is narrower than TableView on iPad, While the TableView is created by code

I want the TableViewCellContentView has the same width with TableView, Here's the code:
#import "ViewController.h"
#interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
#property(strong) UITableView* mainTableView;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, CGRectGetWidth([UIScreen mainScreen].bounds), CGRectGetHeight([UIScreen mainScreen].bounds)-20)];
_mainTableView.delegate = self;
_mainTableView.dataSource = self;
[self.view addSubview:_mainTableView];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: SimpleTableIdentifier];
}
cell.textLabel.text = #"111fewfwFwfrg";
cell.accessoryView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:#"me_today_arrow.png"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
//(lldb) po cell
//<UITableViewCell: 0x13dd22bf0; frame = (0 220; 768 44); text = '111fewfwFwfrg'; autoresize = W; layer = <CALayer: 0x13dd1cf30>>
//(lldb) po cell.contentView
//<UITableViewCellContentView: 0x13c6521a0; frame = (0 0; 711 43.5); opaque = NO; gestureRecognizers = <NSArray: 0x13c6594b0>; layer = <CALayer: 0x13c6546a0>>
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
#end
and here's the image:
http://i.stack.imgur.com/QK6a8.jpg
The lldb says the frame of TableViewCellContentView is (0 0; 711 43.5),the x value is 0 so there might be padding in the TableViewCell, but I can't find any method to set it. BTW, it works fine on iPhone.
Anyone can help me solve the problem?Thank you.
In viewdidload try:
[self.tableView setContentInset:UIEdgeInsetsZero];

tableView re-using indexPath after 10 cells

This is a follow-up to my earlier question. I changed the code to employ non-reusable cells, thinking that somehow cell re-use was duplicating my timers. It still happens. I did an NSLog of the tableView Cells and from the listing you can see that the indexPath starts to repeat after 10 or 11 cells. Why would this be? You can also see that the app entered background mode at row 10 because the message "Saved all of the BNR Items" appears. I swear I did not hit the Home button. But that is what seems to be the cause of the tableView cell re-use: the restoration code isn't working properly, so the indexPath reset to 0.
New code:
#pragma mark -tableView
// **** changelog 10/2/2015 ***************************************
// alternates blue and white rows
- (void)tableView: (UITableView*)tableView
willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{
cell.backgroundColor = indexPath.row % 2
? [UIColor colorWithRed: 0.0 green: 0.3 blue: 1.0 alpha: 0.3]
: [UIColor whiteColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
}
// *********************************************************************
-(NSInteger) tableView:(UITableView *)tableView numberOfSectionsInTableview:(UITableView *)tableview{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[NRCItemStore sharedStore] allItems] count];
}
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"NRCItemCell"];
// Get a new or recycled cell
//NRCItemCell *cell = [tableView dequeueReusableCellWithIdentifier:#"NRCItemCell" forIndexPath:indexPath];
self.timerItem.cell = cell;
[self handleTimer];
NSLog(#"cell for row at index %# is %#", indexPath, cell);
return cell;
}
2015-10-11 12:41:06.398 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740b9f20>
2015-10-11 12:41:06.409 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} is <UITableViewCell: 0x14d52e340; frame = (0 0; 320 44); text = 'panda'; layer = <CALayer: 0x17022e6c0>>
2015-10-11 12:41:16.837 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702a5580>
2015-10-11 12:41:16.840 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000008016> {length = 2, path = 0 - 1} is <UITableViewCell: 0x14d5353a0; frame = (0 0; 320 44); text = 'cub'; layer = <CALayer: 0x17022fb00>>
2015-10-11 12:41:29.777 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740bb660>
2015-10-11 12:41:29.780 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000010016> {length = 2, path = 0 - 2} is <UITableViewCell: 0x14d63c0d0; frame = (0 0; 320 44); text = 'bob'; layer = <CALayer: 0x1742311c0>>
2015-10-11 12:41:44.201 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702a8f40>
2015-10-11 12:41:44.204 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000018016> {length = 2, path = 0 - 3} is <UITableViewCell: 0x14d536810; frame = (0 0; 320 44); text = 'carol'; layer = <CALayer: 0x170224e20>>
2015-10-11 12:41:55.906 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702aae00>
2015-10-11 12:41:55.909 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000020016> {length = 2, path = 0 - 4} is <UITableViewCell: 0x14d639ec0; frame = (0 0; 320 44); text = 'Ted'; layer = <CALayer: 0x17422d180>>
2015-10-11 12:42:08.346 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740be000>
2015-10-11 12:42:08.349 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000028016> {length = 2, path = 0 - 5} is <UITableViewCell: 0x14d50c230; frame = (0 0; 320 44); text = 'Alice'; layer = <CALayer: 0x170230120>>
2015-10-11 12:42:20.786 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702a8d60>
2015-10-11 12:42:20.789 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000030016> {length = 2, path = 0 - 6} is <UITableViewCell: 0x14d51ab40; frame = (0 0; 320 44); text = 'John'; layer = <CALayer: 0x17003aa40>>
2015-10-11 12:42:32.058 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702aac80>
2015-10-11 12:42:32.061 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000038016> {length = 2, path = 0 - 7} is <UITableViewCell: 0x14d63ea20; frame = (0 0; 320 44); text = 'Mary'; layer = <CALayer: 0x17422c9e0>>
2015-10-11 12:42:49.917 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740be420>
2015-10-11 12:42:49.920 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000040016> {length = 2, path = 0 - 8} is <UITableViewCell: 0x14d63f660; frame = (0 0; 320 44); text = 'sue'; layer = <CALayer: 0x17403aba0>>
2015-10-11 12:43:03.588 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740be840>
2015-10-11 12:43:03.590 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000048016> {length = 2, path = 0 - 9} is <UITableViewCell: 0x14d636d40; frame = (0 0; 320 44); text = 'Joan'; layer = <CALayer: 0x17422cce0>>
2015-10-11 12:43:24.583 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1702a8ee0>
2015-10-11 12:43:24.586 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000050016> {length = 2, path = 0 - 10} is <UITableViewCell: 0x14d642ad0; frame = (0 0; 320 44); text = 'sarah'; layer = <CALayer: 0x174230740>>
2015-10-11 12:43:45.782 timeLogger[1447:760103] Saved all of the BNRItems
2015-10-11 12:44:15.109 timeLogger[1447:760103] This was returned from detailViewController <NRCtimerItem: 0x1740b9fe0>
2015-10-11 12:44:15.114 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000058016> {length = 2, path = 0 - 11} is <UITableViewCell: 0x14d646c60; frame = (0 0; 320 44); text = 'Pete'; layer = <CALayer: 0x174230fc0>>
2015-10-11 12:44:17.629 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000058016> {length = 2, path = 0 - 11} is <UITableViewCell: 0x14d642fd0; frame = (0 0; 320 44); text = 'Joan'; layer = <CALayer: 0x17422df00>>
2015-10-11 12:44:19.520 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} is <UITableViewCell: 0x14d622a20; frame = (0 0; 320 44); text = 'Joan'; layer = <CALayer: 0x17422e7c0>>
2015-10-11 12:44:30.359 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0} is <UITableViewCell: 0x14d53b4f0; frame = (0 0; 320 44); text = 'Joan'; layer = <CALayer: 0x17003a800>>
2015-10-11 12:44:30.943 timeLogger[1447:760103] cell for row at index <NSIndexPath: 0xc000000000050016> {length = 2, path = 0 - 10} is <UITableViewCell: 0x14d509080; frame = (0 0; 320 44); text = 'Joan'; layer = <CALayer: 0x170232ca0>>

Odd UITableView tableviewheader changing header height after scroll

this is an odd behaviour I came across and for the life of me can not see where it is happening.
Context, new UITableViewController with 100 rows all saying test. I put another controller view as the tableHeaderView as below. It correctly says the height to be 200. It displays it correctly. Nothing wrong so far.
self.tableView.tableHeaderView = _header.view;
Now when I scroll, I would like to check the height of the header to show and hide the header depending how much is in view.
- (void)showHideHeader:(UIScrollView *)scrollView {
CGPoint offset = scrollView.contentOffset;
NSLog(#"%#",#(offset.y));
if (offset.y < _header.view.bounds.size.height){
if (offset.y > _header.view.bounds.size.height * 0.75) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
} else {
[scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}
}
}
Logging the views at the start and when they are at the scroll method reveals 2 different heights. No other code is in this new table controller.
(lldb) po _header.view
<UIView: 0x7fdf524b18a0; frame = (0 0; 320 200); autoresize = W+H; layer = <CALayer: 0x7fdf524b0de0>>
(lldb) po self.tableView.tableHeaderView
<UIView: 0x7fdf524b18a0; frame = (0 0; 320 200); autoresize = W+H; layer = <CALayer: 0x7fdf524b0de0>>
Then when I log it at the scroll
(lldb) po _header.view
<UIView: 0x7fdf524b18a0; frame = (0 0; 320 58); autoresize = W+H; layer = <CALayer: 0x7fdf524b0de0>>
(lldb) po self.tableView.tableHeaderView
<UIView: 0x7fdf524b18a0; frame = (0 0; 320 58); autoresize = W+H; layer = <CALayer: 0x7fdf524b0de0>>
Any ideas what may be causing this strange change?
edit: posting code for more information, nothing in the header so just posting the main.
#import "MyCallsBaseTableViewController.h"
#import "MyCallsBaseTableHeaderViewController.h"
#interface MyCallsBaseTableViewController ()
#property (nonatomic, strong) MyCallsBaseTableHeaderViewController *header;
#end
#implementation MyCallsBaseTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
if (!_header){
_header = [[MyCallsBaseTableHeaderViewController alloc]init];
self.tableView.tableHeaderView = _header.view;
self.tableView.contentOffset = CGPointMake(0, _header.view.bounds.size.height);
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 100;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell"];
if (!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
}
cell.textLabel.text = #"TEST";
return cell;
}
#pragma mark - scrollview delegates
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
[self showHideHeader:scrollView];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
[self showHideHeader:scrollView];
}
- (void)showHideHeader:(UIScrollView *)scrollView {
CGPoint offset = scrollView.contentOffset;
if (offset.y < _header.view.bounds.size.height){
if (offset.y > _header.view.bounds.size.height * 0.75) {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
} else {
[scrollView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
}
}
}
#end

Get custom UITableViewCell using `cellForRowAtIndexPath`

I have UITableView which use custom UITableViewCell created from .xib file.
And I need to get to some properties of this cells but I always got the same cell.
For example:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WLS_AnswerCell *answerCell = (WLS_AnswerCell *)[tableView dequeueReusableCellWithIdentifier:#"AnswerCellIdentifier" forIndexPath:indexPath];
[answerCell setChecked:NO];
return answerCell;
}
Getting cell's properties:
for (NSInteger j = 0; j < [contentTableView numberOfRowsInSection:0]; j++) {
WLS_AnswerCell *cell = (WLS_AnswerCell *)[(UITableView *)currentView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if (cell.checked) {
NSLog(#"Cell checked, cell %#", cell);
[answers addObject:[NSNumber numberWithInt:j+1]];
}
}
NSlog shows always <WLS_AnswerCell: 0x8de1ee0; baseClass = UITableViewCell; frame = (0 0; 320 40); autoresize = W; layer = <CALayer: 0x8de2070>.
How can I solve this problem?
The error is in your for loop. The index path you create uses i for the row, and it should be j instead :)

dequeueReusableCellWithIdentifier never returns nil

I am using a custom UITableViewCell in my UITableView but the problem is that the cell is never nil when calling the dequeueReusableCellWithIdentifier. Why is this ?
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:#"PHResultTableViewCell" bundle: nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:#"MyCell"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PHResultTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
PackageHolidayItem *obj=[[PackageHolidayItem alloc]init];
obj= [totalArray objectAtIndex:indexPath.row];
cell.packageHolidayItem = obj;
[cell loadRow];
}
return cell;
}
Starting in iOS 5 when you use storyboards and your reuse identifier matches a prototype in your storyboard you will not get a nil returned from dequeueReusableCellWithIdentifier.
From Apple Doc:
Table View Programming Guide for iOS
Creating and Configuring a Table View
Populating a Dynamic Table View with Data
If the dequeueReusableCellWithIdentifier: method asks for a cell
that’s defined in a storyboard, the method always returns a valid
cell. If there is not a recycled cell waiting to be reused, the method
creates a new one using the information in the storyboard itself. This
eliminates the need to check the return value for nil and create a
cell manually.
You can log the cell address to prove to your self they are being reused. But don't ship with the logging it will really slow up your table.
NSLog(#"Deque Cell %p", cell);
Better yet use breakpoint to log it.
$25 = 0x097f9850 <DDSImageSubtitleCheckedTableViewCell: 0x97f9850; baseClass = UITableViewCell; frame = (0 22; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x97f9740>>
$26 = 0x0a6a4a00 <DDSImageSubtitleCheckedTableViewCell: 0xa6a4a00; baseClass = UITableViewCell; frame = (0 66; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0xa6a4b50>>
$27 = 0x0a3ad250 <DDSImageSubtitleCheckedTableViewCell: 0xa3ad250; baseClass = UITableViewCell; frame = (0 110; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0xa3ad390>>
$28 = 0x0a3ae640 <DDSImageSubtitleCheckedTableViewCell: 0xa3ae640; baseClass = UITableViewCell; frame = (0 176; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0xa3ae780>>
$29 = 0x0972a370 <DDSImageSubtitleCheckedTableViewCell: 0x972a370; baseClass = UITableViewCell; frame = (0 220; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0x972a340>>
If you just want the addresses
0x097f9850
0x0a6a4a00
0x0a3ad250
0x0a3ae640
0x0972a370
It does not return nil because you have registered a nib for cell reuse ([[self tableView] registerNib:nib forCellReuseIdentifier:#"MyCell"];).
if dequeueReusableCellWithIdentifier: can't find a cell in the tableviews reuse queue it will instantiate a new one from the nib you have specified.
As others have pointed out if you have registerd a nib to reuse a tableViewCell you are guaranteed to get an instance of cell. If you want to set some value to the cell. You can try modifying your code like this
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
PHResultTableViewCell *cell = (PHResultTableViewCell *)[tableView dequeueReusableCellWithIdentifier:#"MyCell"
forIndexPath:indexPath];];
cell.packageHolidayItem = totalArray[indexPath.row];;
[cell loadRow];
return cell;
}
I don't believe it is supposed to return nil. Why do you want it to?
The method dequeueReusableCellWithIdentifier returns a Cell that is about to be displayed, so it's actually good that it is not null - that way you can modify it as needed.

Resources