1
UITableView
의 각 셀에 UIButton
이 있습니다. 내가 만질 때, 그 상태는 선택되도록 설정됩니다. 그러나 테이블보기를 스크롤하여 단추가 보이지 않도록 상태를 보통으로 설정합니다. UIButton
이 선택된 상태에서 어떻게해야합니까?UITableView에서 UIButton의 선택된 상태
감사합니다.
편집 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (indexPath.row < [messagesArray count]) {
Zprava *msgObj = [messagesArray objectAtIndex:indexPath.row];
int width = 0;
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
width = 320;
} else {
width = 480;
}
CGSize boundingSize = CGSizeMake(width, CGFLOAT_MAX);
CGSize requiredSize = [msgObj.mmessage sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:boundingSize lineBreakMode:UILineBreakModeWordWrap];
UIButton *background = [[UIButton alloc] initWithFrame:CGRectMake(10, 25, 300, requiredSize.height + 20)];
[background setBackgroundImage:[[UIImage imageNamed:@"balloon.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:15] forState:UIControlStateNormal];
[background setBackgroundImage:[[UIImage imageNamed:@"selected-balloon.png"] stretchableImageWithLeftCapWidth:15 topCapHeight:15] forState:UIControlStateSelected];
[background addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
background.tag = msgObj.msgID;
[[cell contentView] addSubview:background];
[background release];
UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 285, 15)];
[dateLabel setFont:[UIFont systemFontOfSize:12]];
[dateLabel setLineBreakMode:UILineBreakModeWordWrap];
[dateLabel setTextColor:[UIColor lightGrayColor]];
[dateLabel setNumberOfLines:0];
[dateLabel setTextAlignment:UITextAlignmentRight];
[dateLabel setText:msgObj.mdate];
[dateLabel setBackgroundColor:[UIColor clearColor]];
[dateLabel setOpaque:NO];
[[cell contentView] addSubview:dateLabel];
[dateLabel release];
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 275, requiredSize.height + 5)];
[messageLabel setFont:[UIFont systemFontOfSize:17]];
[messageLabel setLineBreakMode:UILineBreakModeWordWrap];
[messageLabel setTextColor:[UIColor blackColor]];
[messageLabel setNumberOfLines:0];
[messageLabel setText:msgObj.mmessage];
[messageLabel setBackgroundColor:[UIColor clearColor]];
[messageLabel setOpaque:NO];
[[cell contentView] addSubview:messageLabel];
[messageLabel release];
}
return cell;
}
답장을 보내 주셔서 감사합니다. 하지만 UIButton의 상태가 어떻게 바뀌 었는지 알려주시겠습니까? –
사용자가 탭하면 버튼 상태가 변경됩니까? 따라서 탭 처리기에서해야합니다 – Vladimir
아니요, 상태가 선택에서 정상으로 바뀌었을 때 생각합니다. –