ユーザーがUIButton
テーブルビュー (テーブルビューには各行に複数のボタンがあります) をクリックすると、別のビューが表示されます。ユーザーが他の UIView の [完了] ボタンをクリックした後に、このボタンの画像を変更したいと考えています。どうやってやるの?私は初心者です。コードを教えてください。前もって感謝します。
更新コード:
テーブルビューのコード:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:@"%d,%d",indexPath.section,indexPath.row];
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIButton *market = [UIButton buttonWithType:UIButtonTypeCustom];
[market addTarget:self action:@selector(marketPressedAction:) forControlEvents:UIControlEventTouchDown];
[market setTag:3000];
[market setFrame:CGRectMake(200, 6, 30, 30)];
[cell.contentView addSubview:market];
}
for (UIButton *button in [cell subviews]) { // change name of table here
if ([button isKindOfClass:[UIButton class]]) {
button.tag = indexPath.row;
[button setImage:[UIImage imageNamed:@"Marketplace.png"] forState:UIControlStateNormal];
}
}
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
_tableView.contentInset = UIEdgeInsetsMake(0, 0, 100, 0);
return cell;
}
[開く] ボタンのコード (ユーザーがクリックして別のビューを表示するボタン)
- (void)marketPressedAction:(id)sender
{
UIButton *button = (UIButton *)sender;
buttontag = button.tag;
NSLog(@"Market button click at row %d",buttontag);
}
[完了] ボタンのコード:
-(void)submitMarket
{
for (UIButton *button in [_tableView subviews]) { // change name of table here
if ([button isKindOfClass:[UIButton class]]) {
if (button.tag == buttontag) {
[button setBackgroundImage:[UIImage imageNamed:@"MarketplaceSelect.png"] forState:UIControlStateNormal];
}
}
}
}