如何在表视图上使用textfield显示解析的json

时间:2011-06-22 09:35:06

标签: iphone objective-c ios xcode json

嗨,我是iphone开发新手

我正在使用webservice来连接我在哪里获得json响应字符串,我正在使用JSONvalue解析json responsetring并且我使用按钮在标签上显示解析的json ...

当我点击按钮时,解析的json将显示在标签栏上。

我的问题是可以在用户界面中拥有文本字段,按钮和webview或tableview ..

当我在文本字段中输入特定方法时json文件很大并按下按钮shd在webview或tableview上显示特定方法的内容..

这可能吗?如果是,那么如何实施?

谢谢你

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{


     [connection release];    

    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];


    self.dataWebService = nil;

    NSArray* latestLoans = [(NSDictionary*) [responseString JSONValue] objectForKey:@"loans"]; 
    [responseString release];    


    NSDictionary* loan = [latestLoans objectAtIndex:0];

    //fetch the data

    NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];

    NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];

    float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];

    NSString* name = [loan objectForKey:@"name"];

    NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];

    //set the text to the label
    label.numberOfLines = 0;

    label.text = [NSString stringWithFormat:@"Latest loan: %@ \n \n country:  %@ \n \n µamount $%.2f", name,country,outstandingAmount];

1 个答案:

答案 0 :(得分:0)

如果您想在表格中提供贷款,请阅读UITableViewCell Styles

你将添加你的表,然后指出每个部分的部分数,行数,每个单元格(行)的内容,以及触摸其中一行时该怎么办:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //after turning latestLoans into a property
    return self.latestLoans.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.text=[[self.latestLoans objectAtIndex:indexPath.row] objectForKey:@"name"];
    cell.detailTextLabel.text=[[self.latestLoans objectAtIndex:indexPath.row] objectForKey:@"loan_amount"];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    //do something with the row that was selected, like load a table of detailed information
}