2

IBで作成したuitableviewがあります。そして、私は独自のuitableviewcellを設計しました(これはuiatbleviewcellのサブクラスであり、独自のxibファイルを持っています)。それを私のuitableviewに追加するにはどうすればよいですか?

私は試した

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

static NSString *CellIdentifier = @"myCell";
myCell *cell = (myCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"myCell" owner:self options:nil];
    cell = [xib objectAtIndex:0];
}
// Configure the cell...
cell.title.text = @"tableCell";
cell.preview.text = @"preview";
cell.postedTime.text = @"right now";


return cell;
}

正しく動作しません。担当者が10人であるため、ここに画像を含めることはできません(画像をアップロードするには最低11が必要です)。だからここに私の悪い結果を示すためのリンクがあります。これは私が欲しいものです:http://img708.imageshack.us/img708/5082/20120903153930.png

これは私が持っているものです:http: //img836.imageshack.us/img836/5844/20120903154405.png

4

3 に答える 3

1

uメソッドを使用して各セルのデフォルトの高さを変更する必要があります

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 62.0f; // enter value if u know or test
}

それが役に立てば幸い。ハッピーコーディング:)

于 2012-09-03T13:26:53.723 に答える
1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {
if(btnTag == 1)
    return [array1 count];

if(btnTag == 2)
    return [array2 count];
 return YES;

} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
 return 62;
}


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

static NSString *CellIdentifier = @"Cell";

CustomCell *cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

if(btnTag == 1)
  {
    cell.teamLabel.text = @"i am 'A'cell";
  }
if(btnTag == 2)
  {  
    cell.teamLabel.text = @"i am 'B'cell";
  }
return cell;
}
于 2012-09-03T13:47:33.803 に答える
0

このようにxibファイルに追加する必要はありません。あなたがしたことに応じて、あなたはUITableViewCell別のものにを追加しましたUITableView。本当にカスタムセルを作成しますか?のUITableViewに任意のデータを追加するだけです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 次に、UILabels、UIImageViewsなどのセルを適宜追加します。

 cell = [tableView dequeueReusableCellWithIdentifier:nil];
    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil ];
    }        
    UIButton *Imagebutton = [[UIButton alloc]initWithFrame:CGRectMake(10, 5, 30, 30)];
    UIImage *img = [UIImage imageNamed:@"Lock Unlock.png"];
    [Imagebutton setImage:img forState:UIControlStateNormal];
    [Imagebutton addTarget:self action:@selector(aMethod1:) forControlEvents:UIControlEventTouchDown];
    [cell.contentView addSubview:Imagebutton];
    UILabel *MealsforLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 10, 140, 30)];
    MealsforLabel.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:MealsforLabel];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.textColor=[UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    return cell;

上記のようなもの。

于 2012-09-03T13:27:36.243 に答える