This view probably didn't get initWithFrame: or initWithCoder:
I am using tableView
and implementing it delegates and data source methods. I am not a newbie with tableViews
and delegates. But still I get this crash:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view (<UIView: 0xc8b7a00; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; autoresize = W; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.'
I have used the same code for many others tableViews
that I use to do this, but I do not know where I am going wrong and I also know that this is an old or duplicate question, but none of the previous solutions worked for me. Here are my methods for passing delegates and data sources.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
int numberOfRows = 0;
if(section == 0){
numberOfRows = [self.lotteryArray count];
}else{
numberOfRows = 10;
}
return numberOfRows;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cellToReturn = nil;
LedenactiesCell *cell = (LedenactiesCell *)[self.tableView dequeueReusableCellWithIdentifier:@"LedenactiesCell"];
if(!cell){
NSString *nibName = @"LedenactiesCellView";
[self.cellOwner loadMyNibFile:nibName];
cell = (LedenactiesCell *)self.cellOwner.cell;
}
cell.titleLbl = @"My Text for cell";
cellToReturn = cell;
return cellToReturn;
}
I have debugged my code and it never jumps to the method cellForRowAtIndexPath:
.
Any suggestions..
source to share
maybe you are missing if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){}
in your method initWithStyle:
.
try this hope it will solve your problem.
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
// initialise your objects here...
}
return self;
}
source to share
Make sure you initialize the property before using it. In my case, I initialized the textfield property to viewDidLoad, but I tried to use it somewhere else.
wrong
-(Void)viewDidLoad
{
textField = [UITextField alloc]init];
}
And I am using here
-(void)someMethod
{
textField.text = @"sdsfs";
}
I got error.....
Right way is
-(void)someMethod
{
textField = [UITextField alloc]init];
textField.text = @"sdsfs";
}
I hope it helps to someone.
source to share