2015-05-13 4 views
0

В моем приложении для iPhone я показываю имя & Фамилия на UITableViewCell. Я использовал следующий код. Но я не знаю, как отображать содержимое на UITableViewCell в пределах UITableView.Отображение содержимого на UITableViewCell (Nested NSArray & NSDictionary)

Data Response является: ---

responseObject: 
{ 
    data =  (
       (
         { 
       "created_date" = "2015-05"; 
       description = "Nice blogs..."; 
       "first_name" = John; 
       id = 26; 
       image = "profilethumb.png"; 
       "last_name" = Smith; 
       "ref_id" = 16; 
       reference = blog; 
      } 
     ), 
       (
     ) 
    ); 
    status = success; 
} 

Ниже Код: ---

 NSDictionary *dict=[arrayData objectAtIndex:indexPath.row]; 
     strFirstName=[NSString stringWithFormat:@"%@", [dict objectForKey:@"first_name"]]; 
     strLastName=[NSString stringWithFormat:@"%@", [dict objectForKey:@"last_name"]]; 
     cell1.lblCommenterName.text = [NSString stringWithFormat:@"%@ %@", strFirstName, strLastName]; 

Как я могу отобразить Пользователь Имя & Фамилия на мобильный.

+0

Вы используете UITableView и это метод DataSource и Delegate? –

+0

да! У меня есть –

+0

Я добавил ответ, пожалуйста, проверьте его! –

ответ

1

Пожалуйста, обратитесь код, упомянутый ниже:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    // Dequeue the cell. 
    NSString *cellIdentifier = @"idCellRecord"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 
    // You must have put an Identifier for the UITableViewCell in the Interface Builder. I've given it as "idCellRecord" 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

    // Set the loaded data to the appropriate cell labels. 
    NSDictionary *dict=[[arrayData objectAtIndex:indexPath.row] valueForKey:@"data"]; 


    return cell; 
} 
0

Вы должны были реализованы следующие три основных UITableView методы DataSource,

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return 1; // As you desire to have sections 
} 


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return [arrayData count]; // number of objects within the array 
} 


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    // Dequeue the cell. 
    NSString *cellIdentifier = @"idCellRecord"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; 
    // You must have put an Identifier for the UITableViewCell in the Interface Builder. I've given it as "idCellRecord" 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 

    // Set the loaded data to the appropriate cell labels. 
    NSDictionary *dict=[arrayData objectAtIndex:indexPath.row]; 
    NSString *strFirstName = [dict objectForKey:@"first_name"]; 
    NSString *strLastName = [dict objectForKey:@"last_name"]; 

    [cell.textLabel setText:strFirstName]; 
    [cell.detailTextLabel setText:strLastName]; 

    return cell; 
} 

Примечание:

Я установить UITableView-х Стиль UITableViewCell для «Subtitle» в инструменте IB.

Я предлагаю вам прочитать и привыкают к UITableViews в следующих учебных пособий:

  1. MakeMeGeek
  2. AppCoda 1
  3. AppCoda 2

Я надеюсь, что это будет полезно для вас, чтобы получить сделал то, что вы хотите.

Cheers!