问题描述:

i am having problem with setting the noOfRowsInSection in table view when displaying the current location and when not displaying the current view , it seems that when i set the current location on a "current location" row gets inserted in the table view automatically and messes up the count of rows in noOfRowsInSection (im counting the no of annotations in the map for no of rows) , i solved the problem by simple increasing the no by one when the user is connected to the internet my code:

 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

int countval=[[map annotations] count];

Reachability *reach=[[Reachability reachabilityForInternetConnection] retain];

NetworkStatus status = [reach currentReachabilityStatus];

if (searching)

{

return [copyListOfItems count];

}

else {

if([[self stringFromStatus:status] isEqualToString:@"Connected via wifi"] || [[self stringFromStatus:status] isEqualToString:@"Connected via WWAN"])

{

return countval+1;//

}

else

{

return countval;

}

}

}

but , now im having problem while reloading the table using

[self.tableView reloadData];

the numberOfRowsInSection gets refreshed and messes up again , how can i set the numberOfRowsInSection again while being refreshed or is there another way to fix this problem, i would be really grateful and thankful for any suggestions, code , tutorials . Thanking you in advance

网友答案:

Found the problem , when reloading the table view my code:

    return countval+1;

just keeps adding 1 to numberOfRowsInSection so it gives you array out of bound error , which i fixed by simply putting a constant number 87 which is the count of annotations on my map , not the best solution but since my annotations count is fixed , it solved the problem.

return 87;
相关阅读:
Top