Reputation: 887
Now the tableView loads but when I try to scroll down the table the app crashes. Heres my code:
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"ince mal");
NSLog(@"%f", i);
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}
// fill it with contents
TFHppleElement * element = [searchResults objectAtIndex:indexPath.row];
NSString * tagContent = [element content];
cell.textLabel.text = tagContent;
return cell;
}
Upvotes: 1
Views: 2281
Reputation: 1
There is nothing wrong with your TableView, only the way you use it. In the class you use it it is allocated, initialized and shown. But I bet you don't hold a pointer to it that keeps it from getting garbage collected.
Upvotes: 0
Reputation: 864
I am not seeing anything bad in these code. The content filling lines may cause some problem. I dont even find any release in your question. CellForRow gets fired whenever you tried to scroll. So check for the array, for accessing its object.
Upvotes: 0
Reputation: 15115
You havent allocated element and you try to release it. thats the problem.
Remove [element release]
from your code.
Any object with retain count 0 get released, then it will crash.
Set NSZombieEnabled to check which object get released.
EDIT:
Remove this lines also,
if (i == indexPath.row) {
return nil;
}
[tagContent release];
If you want an empty cell then return as,
if (i == indexPath.row) {
return cell; //Before adding any cell contents.
}
Upvotes: 2
Reputation: 16709
Never do this (that would lead you to another crash (assertion failure)):
if (i == indexPath.row) {
return nil;
}
As for your crash:
[element release];
[tagContent release];
remove these lines
Upvotes: 0