Fetching JSON data after failed retrieval

血红的双手。 提交于 2019-12-02 11:28:52

Sounds like you are getting back an empty response, so that null check always resolves to true. Try checking if the count of the NSArray is greater than 0 instead of if(self.jobs != nil)

Just change if(self.jobs != nil) to if([self.jobs count] > 0).

if([self.jobs count] > 0)
{
    [self.tableView reloadData];
}
else
{
    UIAlertView* alert_view = [[UIAlertView alloc]
                               initWithTitle: @"Failed to retrieve data" message: nil delegate: self
                               cancelButtonTitle: @"cancel" otherButtonTitles: @"Retry", nil];
    [alert_view show];
}

You might also want to do a null check before you try and do the count to avoid any null reference exceptions:

if(self.jobs != nil && [self.jobs count] > 0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!