-1

私が持っているグループ UITableView に文字列「ハンドル」を入力するのに問題があります。

  for(NSDictionary * dataDict in servers) {

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

}

これを for ステートメントを使用して、ハンドルを使用して新しいセルを動的に作成する方法について、私は完全に混乱しています。

実際の UITableView はメイン ビュー コントローラー上にあり、セルはありません。値をループしてラベル付きのセルを作成するにはどうすればよいですか?

4

3 に答える 3

1

のこのデータソース メソッドを上書きするUITableView必要があります。テーブルのデータソースを設定することを忘れないでください。サーバーアレイがいっぱいになったら、データをリロードするだけです。[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;
}
于 2013-08-09T12:58:37.147 に答える
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;
}

ここで mycustomcell は、tableview のセルではなく Custome セルです...これがうまくいくことを願っています.. mycustomecell という名前の新しい custome セルを .h 、.m および .xib で作成します。

于 2013-08-09T12:57:45.490 に答える
0

UITableViewDataSource プロトコルで利用可能な以下のメソッドを使用する必要があります。

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
于 2013-08-09T12:58:23.943 に答える