vaibhava
vaibhava

Reputation: 47

Regarding Crash app in iphone

below code is working in ios 6 , but in ios 7 it is cause of crash app at the point of "indexPathForCell". help me to resolve this problem.. there is table view in which we are clicking in a cell and moving in a second view again table view is going to be load with data...but before that app crash..

Thanks in advance

UIView *view = [self superview]; 
// Find TableViewCell
if(view != nil && ![view isKindOfClass:[UITableView class]]) view = [view superview];

UIView *cellView = [self superview];
// Find TableViewCell
if(cellView != nil && ![cellView isKindOfClass:[UITableViewCell class]]) cellView = [cellView superview];

if(view != nil && cellView != nil) {
    UITableViewCell *cell = (UITableViewCell*)cellView.superview.superview;
    UITableView *tableView = (UITableView*)view;

    if([tableView style] == UITableViewStyleGrouped)
    {
        NSIndexPath *path = [tableView indexPathForCell:(UITableViewCell*)cell];
        if(path) {
            int count = [tableView numberOfRowsInSection:[path section]];

Upvotes: 0

Views: 107

Answers (1)

Itesh
Itesh

Reputation: 199

UITableViewCell cell = (UITableViewCell)cellView.superview.superview.superview;

For ios7 you need to add one more superview.

Your app is getting crashed due to this

[tableView indexPathForCell:(UITableViewCell*)cell];

because cell is nil.

You need to add a check for ios 7 and ios 6. For ios 7 Add another superview it will solve the purpose.

Upvotes: 3

Related Questions