ObjectiveC - Crash while loading tableView Cells
I have written this method in objectiveC (for iOS but that immaterial). My app crashes when calling this method. I am writing all this in my .m
file. Am not able to figure out the reason for the crash...
-(UITableViewCell *)myCell:(UITableViewCell *)cell
forRowIndex:(NSIndexPath *)indexPath
{
//customize the cell.
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellId = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellId];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ResultsOne" owner:self options:nil];
cell = self.resultsOne;
}
cell = [se开发者_运维百科lf myCell:cell:indexPath]; //code crashes here
return cell;
}
What am i doing wrong ?
You need to write the method call like this:
cell = [self myCell:cell forRowIndex:indexPath];
please check the signature of the method "myCell:" .
as @Robert Fratto pointed out it might be some thing else.
Document says:
[myRectangle setOrigin:30.0 :50.0]; // This is a bad example of multiple arguments
Since the colons are part of the method name, the method is named setOrigin::. It has two colons as it takes two arguments. This particular method does not interleave the method name with the arguments and, thus, the second argument is effectively unlabeled and it is difficult to determine the kind or purpose of the method’s arguments.
Because you are missing method signature while calling. Below is the correction.
Your Call:
cell = [self myCell:cell:indexPath]; //code crashing here...!
Actual Call :
cell = [self myCell:cell forRowIndex:indexPath]; // It'll work for sure as we following the correct method signature from your above code.
You need to write the method call like this:
if(cell == nil)
{
cell = [[[NSBundle mainBundle] loadNibNamed:@"ResultsOne"owner:self options:nil] objectAtIndex:0];
}
Than after, you call:
cell = [self myCell:cell forRowIndex:indexPath];
精彩评论