0

iOSアプリケーションを開発していますが、RestKitを使用してサーバーから取得した文字列としてデータがあります。データは正常に取得され、NSlogを使用して印刷できます。したがって、これらのデータを以下のtableviewcellで表示したいと思います。

ここに画像の説明を入力してください

それで、RestKitを使用してサーバーから取得したデバイス、説明、および日付のリストで埋められるようにtableviewcellを実装する方法。

前もって感謝します。

4

4 に答える 4

0

セルの高さを設定します

tableView.rowHeight=height_you_want;
        or
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return your_row_height;
}

内部cellForRowAtIndexPath: 3 つの UILabel を作成し、変更 (背景テキストのフォントの色のサイズなど) して、サブビューとして cell または cell.contentView に追加できます。

UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(<#CGFloat x#>, <#CGFloat y#>, <#CGFloat width#>, <#CGFloat height#>)];    
lbl.text=@"Your text";
lbl.backgroundColor=[UIColor clearColor];    
[cell addSubview:lbl];

//use this accessory type     
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
于 2012-08-22T11:15:10.330 に答える
0

カスタム セルを xib で作成します。

@interface YourCustomCell : UITableViewCell
@property(nonatomic, strong) IBOutlet UILabel* deviceNameLbl;
@property(nonatomic, strong) IBOutlet UILabel* desciptionLbl;
@property(nonatomic, strong) IBOutlet UILabel* dateLbl;
@end

@implementation
@synthesize deviceNameLbl ,.......
......

ここに画像の説明を入力 次に、このセルを表示するView Controllerで。

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    static NSString* cellIdentifier = @"YourCustomCell";
    YourCustomCell *cell = (YourCustomCell*)[tableView dequeueReusableCellWithIdentifier:cellType];
     if (cell == nil) {
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:nil options:nil];
    cell = (YourCustomCell*)[nib objectAtIndex:0];
      }

   //yourDataArray is a array contains NSDictionary
   cell.deviceNameLbl = [[yourDataArray objectAtIndex:indexPath.row]objectForKey@"deviceName"];
   cell.desciptionLbl = [[yourDataArray objectAtIndex:indexPath.row]objectForKey@"description"];
   cell.dateLbl = [[yourDataArray objectAtIndex:indexPath.row]objectForKey@"date"];

   return cell;
}
于 2012-08-22T11:16:25.930 に答える
0
  1. カスタムを作成する必要がありますUITableViewCell
  2. あなたのデータ配列をループするUITableViewController
  3. クラスを割り当て- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath/初期化する必要があります

しかし、@FaddishWormが言うように、それには時間がかかります

于 2012-08-22T11:16:38.643 に答える
0

This is easy, but takes a bit of time. You need to get your backend data into arrays (or something similar) - inside a class that extends UITableViewController, then hook up your UILabels as outlets, and in the tableView:cellForRowAtIndexPath function, you can pull assign the data to a cell at a particular index.

cell.deviceDescription.text = [myDataArray objectAtIndex:[indexPath row];

于 2012-08-22T11:13:01.620 に答える