iOSアプリケーションを開発していますが、RestKitを使用してサーバーから取得した文字列としてデータがあります。データは正常に取得され、NSlogを使用して印刷できます。したがって、これらのデータを以下のtableviewcellで表示したいと思います。
それで、RestKitを使用してサーバーから取得したデバイス、説明、および日付のリストで埋められるようにtableviewcellを実装する方法。
前もって感謝します。
iOSアプリケーションを開発していますが、RestKitを使用してサーバーから取得した文字列としてデータがあります。データは正常に取得され、NSlogを使用して印刷できます。したがって、これらのデータを以下のtableviewcellで表示したいと思います。
それで、RestKitを使用してサーバーから取得したデバイス、説明、および日付のリストで埋められるようにtableviewcellを実装する方法。
前もって感謝します。
セルの高さを設定します
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;
カスタム セルを 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;
}
UITableViewCell
UITableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
/初期化する必要がありますしかし、@FaddishWormが言うように、それには時間がかかります
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];