Как поместить UIButton в ячейку uitableview? - PullRequest
1 голос
/ 26 мая 2011

Я могу создать tableview с textlabel и с detaillabeltext.

Кроме того, можно ли добавить UIButton в ячейку.

Я имею в виду после детализации текста, могу ли я поместить UIButton (например, кнопку «Удалить»)

В настоящее время у меня есть следующий код

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//-----------------------------------------------------------------------------------------------------
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    profileName = [appDelegate.sentItemsList objectAtIndex:indexPath.row];

    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    NSString *subjectData = [profileName.sent_subject stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

    cell.textLabel.text = [NSString stringWithFormat: @"%@ ", subjectData];

    cell.textLabel.font = [UIFont boldSystemFontOfSize:13];


    NSString *CompanyName = [profileName.sent_content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];

    cell.detailTextLabel.text = [NSString stringWithFormat: @"%@ ",CompanyName];

    cell.detailTextLabel.font = [UIFont systemFontOfSize:10];

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

    cell.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:249.0/255.0 blue:230.0/255.0 alpha:2.0];

    return cell;
}

Спасибо за ваше время и помощь!

Ответы [ 2 ]

6 голосов
/ 26 мая 2011
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
 forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[cell addSubview:button];
2 голосов
/ 26 мая 2011

Вы можете добавить кнопку или любой другой элемент управления к представлению содержимого ячейки.

UIButton *cellButton = [[UIButton alloc]init];
[cellButton addTarget:self action:@selector(uploadData:)forControlEvents:UIControlEventTouchDown];
[cellButton setTitle:@"Upload Now" forState:UIControlStateNormal];
cellButton.frame = CGRectMake(100, 180, 150, 35);
[cell.contentview addSubview:cellButton];
[cellButton release];

Добавить любой элемент управления в представление содержимого ячейки

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...