表视图的重新加载方法没有重新加载

时间:2015-08-10 15:00:14

标签: ios objective-c uitableview

我正在尝试从JSON获取数据。它是第一次在表格视图中出现,但第二次没有重新加载数据。

enter image description here

-(void)textFieldChange:(UITextField *)textfield
{
    [tbl1 reloadData];
    if (textfield.text.length==2)
    {
        NSString *post = [NSString    stringWithFormat:@"domain=MyPera&key=MyPera&email=%@&password=%@&action=MyPera&term=MyPera"];

        ///// CHANGE ////////////////
        NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
        NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[post length]];

        NSMutableURLRequest *ret = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"URL"]];

        [ret setHTTPMethod:@"POST"];
        //[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [ret setValue:postLength forHTTPHeaderField:@"Content-Length"];
        [ret setHTTPBody:postData];

        NSURLResponse *response=nil;
        NSError *error=nil;

        NSData *newData = [NSURLConnection sendSynchronousRequest:ret    returningResponse:&response error:&error];
        //json parse
        NSString *responseString = [[NSString alloc] initWithData:newData encoding:NSUTF8StringEncoding];
        NSLog(@"Response :%@",responseString);

        NSData *jsonData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *e;
        array2 = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&e];
        avar=[[NSMutableArray alloc]init];
        rec_id=[[NSMutableArray alloc]init];
        for (int i=0; i<array2.count; i++)
        {
            [avar addObject:[[array2 objectAtIndex:i] objectForKey:@"value"]];
            [rec_id addObject:[[array2 objectAtIndex:i] objectForKey:@"uid"]];
        }
        //[tbl1 reloadData];
    }
    else if (txt1.text.length==1)
    {
        tbl1.dataSource=nil;
        avar=nil; //avar is mutable data....
        [tbl1 reloadData];
    }
}

我使用搜索作为类型功能它第一次工作得更好但是当我按退格键或删除字符表视图时不显示数据。我还声明了表的数据源和委托,但没有工作。

0 个答案:

没有答案