2013-08-09 2 views
-1

"handle"문자열을 그룹 UITableView에 입력하는 데 문제가 있습니다.JSON 배열을 반복하고 그룹화 된 UITableView에 문자열을 입력하십시오.

for(NSDictionary * dataDict in servers) { 

    NSString * handle [dataDict objectForKey:@"handle"]; 

} 

동적으로 명령문을 사용하여 핸들을 사용하여 새 셀을 만드는 방법에 대해 완전히 혼란 스럽습니다.

실제 UITableView는 주보기 컨트롤러에 있으며 셀이 없습니다. 값을 반복하고 레이블이있는 셀을 만드는 방법은 무엇입니까? 여기 mycustomcell

답변

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [arrData count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"SimpleTableCell"; 

    mycustomcell *cell = (mycustomcell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 

    if (cell == nil) 
    { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"mycustomcell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
     NSLog(@"NIB = %@",nib); 
     NSLog(@"Cell = %@",cell); 
    } 

    cell.lblName.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Name"]; 
    cell.lblId.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Id"]; 
    cell.lblGender.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Gender"]; 
    cell.lblAddress.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Address"]; 
    cell.lblPhone.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Phone"]; 
    cell.lblEmail.text = [[arrData objectAtIndex:indexPath.row] objectForKey:@"Email"]; 

    NSLog(@"tbl %@",cell.lblName.text); 


    return cell; 
} 
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 200; 
} 

는 손님 여러분 전지하지의 tableview의 세포입니다 ... 나는이 당신을 위해 일하는 희망 .. 당신은해야

+1

당신은 셀이 전무 있는지 확인하고 펜촉을로드하는 데 더 이상 필요하지 않습니다, 데이터를 다시로드 :)! –

+0

ohh ok thanx 나는 이런 것들을 안다. :) –

+0

Raphael이 틀렸다.'dequeueReusableCellWithIdentifier :'는 아직 캐시되지 않은 셀에 대해 nil을 리턴한다. 'dequeueReusableCellWithIdentifier : forIndexPath :'는 캐시되지 않은 셀에 대해 새로운 셀 객체를 생성합니다. – vikingosegundo

0

.. mycustomecell .H,하는 .m 및 .xib로 명명 된 새로운 손님 셀을 만들기 UITableViewDataSource 프로토콜에서 사용할 수있는 아래의 메서드를 사용하십시오.

1

UITableView에 대해이 데이터 소스 방법을 덮어 쓰려면 테이블의 데이터 소스를 설정하는 것을 잊지 마십시오. 당신이 당신의 서버 배열을 입력하면 그냥 dequeueReusableCellWithIdentifier가 벌써 않기 때문에 [table reloadData];

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return servers.count; //will create cell based on your array count 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    //show handle stirng from server array 
    cell.textlabel.text = [[server objectAtIndex:indexPath.row]objectForKey:@"handle"]; 

    return cell; 
} 
+0

내가 테이블 뷰의 데이터 소스를 최대 후크 –

+0

[iITableView 데이터 소스 및 델리게이트 설정에 대한 자습서 비디오보기] (https://www.youtube.com/watch?v=9eog-Y_Beww) – Hemang

관련 문제