2017-06-12 31 views
-2

我正在用JSON链接做一个项目。如何显示来自目标c中JSON链接的一个标签中的4个值之一?

因此,雇员的休假是作为休闲5,紧急2,休假3,医疗0给予的。

在JSON链接中,它是单独给出的。

"employee_casual_leave":0,"employee_medical_leave":0,"employee_annual_leave":0,"employee_emergency_leave":1 

但在我的代码中,我必须将它们中的任何一个放在一个标签中。即应该在标签中显示一个人带走的类型。

我已经把一个标签,在厦门国际银行,并设置我的cellForRowAtIndexPath如下:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; { 
    static NSString *CellIdentifier = @"cel"; 

    NSString *str=[NSString stringWithFormat:@"%ld",(long)indexPath.section]; 

    NSUserDefaults *UserDefaults = [NSUserDefaults standardUserDefaults]; 
    [UserDefaults setObject:str forKey:@"leaveCount"]; 
    [UserDefaults synchronize]; 

    cell1=[self.tab1 dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell1==nil) { 
     NSArray*toplevelobject=[[NSBundle mainBundle] loadNibNamed:@"emp_leave_list" owner:self options:nil]; 
     cell1=[toplevelobject objectAtIndex:0]; 
    } 
    NSString *s7=[[[Dict1 objectForKey:@"employee_list"]objectAtIndex:indexPath.section ]objectForKey:@"employee_other_leave"] ; 

    NSString *s700= [NSString stringWithFormat:@"%@", s7]; 

    cell1.leave_type.text=s7; 

    return cell1; 
} 

在标签“leave_type”我想要显示的类型的离开员工采取其是否临时或紧急情况或他人或假期。请尽快给我一个答案。

+0

先在这里添加完整的JSON和格式化你的代码。 – ChanWarde

+0

任何人都知道我的问题的答案? –

+0

添加您的完整JSON响应 – ChanWarde

回答

0

1)在解析方法JSON和申报YourViewController.h一个数组文件

NSMutableArray *arrEmployee; 

-(void)getEmployeeDetail:(NSDictionary *)jsonResponse 
{ 
     arrEmployee = [jsonResponse objectForKey:@"employee_list"]; 
     [yourTable reloadData]; 
} 

2)添加的tableview委托

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
    } 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
     return arrEmployee.count; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    YourCell *cell = (YourCell *)[tableView dequeueReusableCellWithIdentifier:@"YourCellIdentifier"]; 

    NSDictionary *info = [arrEmployee objectAtIndex:indexPath.row]; 
    cell.lblLeave = [info objectForKey:@"employee_annual_leave"]; 

    return cell; 
} 
相关问题