У меня есть следующий код, который создает мой UITableViewCell ...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSNumberFormatter *numberFormatter = nil;
if (numberFormatter == nil) {
numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
[numberFormatter setMaximumFractionDigits:3];
}
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
UIImage *image = [UIImage imageNamed:@"home1"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
button.tag = indexPath.row;
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(setHomeButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
UIImage *imageShare = [UIImage imageNamed:@"arrows-share"];
UIButton *buttonRight = [UIButton buttonWithType:UIButtonTypeCustom];
buttonRight.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
[buttonRight setBackgroundImage:imageShare forState:UIControlStateNormal];
[buttonRight setFrame: CGRectMake( 220.0f, 0.0f, imageShare.size.width, imageShare.size.height)];
[buttonRight addTarget:self action:@selector(shareLink:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:buttonRight];
}
Event *event = (Event *)[eventsArray objectAtIndex:indexPath.row];
cell.textLabel.text = [event name];
NSString *string = [NSString stringWithFormat:@"%@, %@",
[numberFormatter stringFromNumber:[event lat]],
[numberFormatter stringFromNumber:[event lon]]];
cell.detailTextLabel.text = string;
return cell;
}
Это прекрасно работает в портретной, но в альбомной ориентации, когда повернутая кнопка UIB "buttonRight" не остается рядом с дополнительным видом.Возможно ли это без создания всего этого в IB?
