3

プログラムでカスタム UITableViewCell を作成しましたが、IB で作成された UITableViewController の UITableView に追加したいと考えています。どうやってやるの?

4

2 に答える 2

2

これを試して -

cellForRowAtIndexPath メソッドで、次のようにカスタム セルを追加します -

static NSString *CellIdentifier = @"DashboardCell";

DashboardTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[DashboardTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

セルに画像、テキストなどが含まれている場合は、次のように追加します-

cell.image.image = [UIImage imageNamed:[apdelobj.array1_25 objectAtIndex:myInt]];

cell.titleLabel.text = dashboardList.mistohMessage;
于 2013-10-30T09:41:52.977 に答える
0

UITableViewDataSourceのデリゲート メソッド-(UITableViewCell*)tableView:(UITableView*)t cellForRowAtIndexPath:(NSIndexPath*)indexPathは、プログラムまたは IB でセルがどのように作成されたかに関係なく、まさにそのためのものです。このメソッドから作成したセルを返すだけです。作成したセルにデータを入力することを忘れないでください。

したがって、UITableViewDataSourceメソッドを提供しています。上記を除いて、このデリゲートにはもう 1 つの必須メソッド-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section. 他のすべては必須ではありませんが、多くの場合便利です。UITableViewDataSourceプロトコルリファレンスを参照してください。

于 2013-06-14T15:49:49.443 に答える