1

テーブル ビューがあり、セクション 2 番目の行にボタンを配置しました。テーブル ビューをスクロールすると、このボタンは他の行にも表示されます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *kCellID = @"cellID";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];/////self...ramesh
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kCellID];
    }

    if (indexPath.row==1)
    {
        cell.accessoryView=[[UIView alloc]initWithFrame:self.warmUpSwitch.frame];
        cell.textLabel.text=@"Warm Up(5 min.)";
        [cell.accessoryView addSubview:self.warmUpSwitch];
    }
    if (indexPath.row==2)
    {
        cell.accessoryView=[[UIView alloc]initWithFrame:self.coolDownSwitch.frame];

        cell.textLabel.text=@"Cool Down(5 min.)";
        [cell.accessoryView addSubview:self.coolDownSwitch];
    }
}
4

1 に答える 1

0

これを試して、

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];


}
  if (indexPath.row==1)
    {

     UIButton *btnwarmUpSwitch = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
     btnwarmUpSwitch.frame = CGRectMake(250,20,100,50);  //set frame where you want to set
    [btnwarmUpSwitch setTitle:@"Warm Up(5 min.)" forState:UIControlStateNormal];
     btnwarmUpSwitch.tag=indexPath.row;
    [btnwarmUpSwitch addTarget:self action:@selector(selectwarmUpSwitch:) forControlEvents:UIControlEventTouchUpInside];
     [cell.contentView addSubview:btnwarmUpSwitch];


    }
    if (indexPath.row==2)
    {
        UIButton *btncoolDownSwitch = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
     btncoolDownSwitch.frame = CGRectMake(250,20,100,50);  //set frame where you want to set
    [btncoolDownSwitch setTitle:@"Cool Down(5 min.)" forState:UIControlStateNormal];
     btncoolDownSwitch.tag=indexPath.row;
    [btncoolDownSwitch addTarget:self action:@selector(selectcoolDownSwitch:) forControlEvents:UIControlEventTouchUpInside];
     [cell.contentView addSubview:btncoolDownSwitch];
    }
   return cell;
 }
 - (void) selectwarmUpSwitch:(id)sender
 {

 }
 - (void) selectcoolDownSwitch:(id)sender
 {

 }
于 2013-02-23T04:30:29.077 に答える