Hi
As the title says, I have a problem implementing a button in an accessory view.
Let me explain...
I have a custom tableview controller and when the cells are being populated with content, the accessoryview is additionally set up containing a UIButton that calls a local function upon UIControlEventTouchUpInside.
It nearly works...but the button in the accessoryview only calls the action when I touch the left half of the button???
Some of my code is below...is it sufficient ?
As the title says, I have a problem implementing a button in an accessory view.
Let me explain...
I have a custom tableview controller and when the cells are being populated with content, the accessoryview is additionally set up containing a UIButton that calls a local function upon UIControlEventTouchUpInside.
It nearly works...but the button in the accessoryview only calls the action when I touch the left half of the button???
Some of my code is below...is it sufficient ?
Code:
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
Class listClass = NSClassFromString(self.listItemClass);
cell = [[[listClass alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.textLabel.font = kItemFont;
cell.textLabel.adjustsFontSizeToFitWidth = kItemFontShrink;
cell.detailTextLabel.font = kItemSubtitleFont;
}
if (self.listItems != nil && self.listItems.count > indexPath.row) {
NSDictionary *listItem = [self.listItems objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:[listItem objectForKey:kKeyItemIcon]];
cell.textLabel.text = [[listItem objectForKey:kKeyItemText] uppercaseString];
cell.detailTextLabel.text = [[listItem objectForKey:kKeyItemSubtitleText] uppercaseString];
NSString *textColorString = [listItem objectForKey:kKeyItemTextColor];
NSString *subtitleColorString = [listItem objectForKey:kKeyItemSubtitleTextColor];
cell.textLabel.textColor = (textColorString != nil) ? [self _colorFromString:textColorString] : kItemFontColor;
cell.detailTextLabel.textColor = (subtitleColorString != nil) ? [self _colorFromString:subtitleColorString] : kItemSubtitleFontColor;
NSDictionary *accessoryObject = [listItem objectForKey:kKeyItemAccessoryObject];
if (accessoryObject != nil) {
UIButton *accessoryButton = [UIButton buttonWithType:UIButtonTypeCustom];
accessoryButton.frame = CGRectMake(0, 0, 200, 100);
[accessoryButton setImage:[UIImage imageNamed:[accessoryObject objectForKey:kKeyAccessoryIcon]] forState:UIControlStateNormal];
[accessoryButton setBackgroundColor:[UIColor blueColor]];
[accessoryButton addTarget:self action:@selector(_didTapAccessoryButton: ) forControlEvents:UIControlEventTouchUpInside];
[cell setAccessoryView:accessoryButton];
} else {
cell.accessoryView = nil;
}
} else {
cell.imageView.image = [UIImage imageNamed:@"orange_cirkel"];
cell.textLabel.text = @"LIST ITEM";
cell.detailTextLabel.text = @"ADDITIONAL TEXT";
}
return cell;
}
Last edited by a moderator: