1

TaskCell という UITableViewCell のクラスを作成し、.xib ファイルを設計して、ファイルの所有者をカスタム クラスに接続しました。次に、View Controller クラスでカスタム デザインをロードしたいのですが、表示されません。これは、テーブル ビューを使用するビュー コントローラーのコードです。

ShowTaskViewController.h ファイル:

@interface ShowTaskViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
    //Database object
    sqlite3 *taskeeDB;
    NSString *databasePath; 
}
@end

インデックス パス メソッドの行のセルを含む ShowTaskViewController.m ファイル:

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

    //Get data for cell
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    Task *taskObj1 = (Task *)[appDelegate.taskArray objectAtIndex:indexPath.row];
    NSString *sName = [[NSString alloc] initWithFormat:@"%@",taskObj1.name];
    NSString *sLoc = [[NSString alloc] initWithFormat:@"%@",taskObj1.location];
    NSString *sTime = [[NSString alloc] initWithFormat:@"%@",taskObj1.time];
    NSString *sDate = [[NSString alloc] initWithFormat:@"%@",taskObj1.date];

    //Configure cell if null
    if (cell == nil) {
        //I have written a custom init method to take parameters and assign label text values
        cell = [[TaskCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier name:sName location:sLoc time:sTime date:sDate];
    }
return cell;
}

セルがデキュー セル リストから null の場合、TaskCell がカスタム UITableViewCell クラスである新しいセル オブジェクトを割り当てています。私は正しいプロセスを行っていますか?

Show 次のようにセルを作成しようとしていますか?

if (cell == nil){
    NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"TaskCell" owner:self options:nil];
    for (id currentObjects in objects  ) { 
        if ([currentObjects isKindOfClass:[UITableViewCell class]]) {
            cell = (TaskCell*) currentObjects;
            break;
        }
    }
}
4

1 に答える 1

1

次の変更が役立つと思います!!

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {

    static NSString *CellIdentifier = @"Cell"; 
    TaskCell *cell = (TaskCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    //Get data for cell
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    Task *taskObj1 = (Task *)[appDelegate.taskArray objectAtIndex:indexPath.row];
    NSString *sName = [[NSString alloc] initWithFormat:@"%@",taskObj1.name];
    NSString *sLoc = [[NSString alloc] initWithFormat:@"%@",taskObj1.location];
    NSString *sTime = [[NSString alloc] initWithFormat:@"%@",taskObj1.time];
    NSString *sDate = [[NSString alloc] initWithFormat:@"%@",taskObj1.date];

    //Configure cell if null
    if (cell == nil) {
        //I have written a custom init method to take parameters and assign label text values
        cell = [[TaskCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier name:sName location:sLoc time:sTime date:sDate];
    }
return cell;
}
于 2012-07-24T06:10:52.513 に答える