【问题标题】:JSON loading ProgressViewJSON 加载 ProgressView
【发布时间】:2014-02-23 10:04:24
【问题描述】:

当我从 JSON 加载一些数据时,我想制作一个 UIProgressView。 这就是我用来获取 JSON 数据的代码:

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == searchTextField)
    {
        [searchTextField resignFirstResponder];
        [self loadData];

    }

    return YES;
}



-(void)loadData
{

    NSString *urlString = [NSString stringWithFormat:@"mydomain.com/search/getEvents.php?searchQuery=%@", searchTextField.text];
    NSURL *searchURL = [NSURL URLWithString:urlString];
    dispatch_async(kBgQueue, ^{
        NSData *data = [NSData dataWithContentsOfURL:searchURL];
        [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];

    });
}


-(void)fetchedData:(NSData*)responseData
{
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

    [fetchedResutsArray release]; // release old instance
    fetchedResutsArray = [[json objectForKey:@"Events"] retain];

    NSLog(@"%@", fetchedResutsArray);

    if (fetchedResutsArray != nil)
    {
        [self.tableView reloadData];
    }
    else if (fetchedResutsArray == nil)
    {
        UIAlertView *noResultsAlert = [[UIAlertView alloc] initWithTitle:@"No Results" message:@"There are no results" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
        [noResultsAlert show];
        [noResultsAlert release];
    }

}

谁能帮我创建一个显示当前下载进度的进度视图?

【问题讨论】:

    标签: ios iphone json progress-bar


    【解决方案1】:

    您可以使用MBProgressHud
    当您想在视图上添加/显示进度界面时,只需调用

    [MBProgressHUD showHUDAddedTo:self.view animated:YES];

    然后隐藏/停止您可以调用
    [MBProgressHUD hideHUDForView:self.view animated:YES];

    【讨论】:

    • @profidash_98 好的...如果您有任何与此相关的问题,请询问
    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多