6/01/2009

Sell items

I finally implemented selling items at the shop. Added in info button for the items so that will will display detailed view of each items. It's an little property called accessoryView in UITableViewCell.

ショップでアイテムが売れるようになった。自分のアイテムのinfoも見れるようなった。UITableViewCellでaccessoryViewというのにボタンを指定するだけ。


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

....

UIButton *anAccessory = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *aImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"icon_info" ofType:@"png"]];
[anAccessory setBackgroundImage:aImage forState:UIControlStateNormal];
anAccessory.frame = CGRectMake(0, 0, 24, 24);
anAccessory.showsTouchWhenHighlighted = YES;
[anAccessory addTarget:self action:@selector(tappedAccessory:withEvent:) forControlEvents:UIControlEventTouchUpInside];
anAccessory.userInteractionEnabled = YES;
cell.accessoryView = anAccessory;



- (void)tappedAccessory:(UIControl *)button withEvent:(UIEvent *)event{
NSIndexPath *indexPath = [self.theTableView indexPathForRowAtPoint: [[[event touchesForView: button] anyObject] locationInView: self.theTableView]];
NSLog(@"%i", indexPath.row);
}

No comments:

Post a Comment