-8

次のコンポーネントを持つストーリーボードを使用してカスタム セルを作成しました。

1 UIImage 2 UILabels 4 UIbutton

1 つのボタンを使用すると、ユーザーはクーポンをお気に入りとして保存できます。ユーザーがクーポンを保存した後、このボタンを無効に設定したいと思います。カスタム セル クラスのボタンに IBOutlet を追加しようとしましたが、機能しません。エラーが発生します。これどうやってするの?誰かが私を助けることができますか?

コード:

CouponsCell.h

@property (nonatomic, strong) IBOutlet UIButton *saveFav;

CouponsCell.m

#import "CouponsCell.h"

@implementation CouponsCell
@synthesize saveFav;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end

IBOutlet とボタンを接続し、ユーザーがボタンに触れたときにこれを試しました。

- (IBAction)AddFavorite:(id)sender {

    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
    NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];
    Coupons * couponsObjects = [self.fetchedResultsController objectAtIndexPath:indexPath];

    CouponsCell *couponsCell = [self.tableView dequeueReusableCellWithIdentifier:@"CouponCell" forIndexPath:indexPath];

    idCoupon = cuponesObjects.idCoupons;

    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    [reachability startNotifier];
    NetworkStatus status = [reachability currentReachabilityStatus];

    if ( status == NotReachable )
    {
        UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"CC Galerias"
                                                          message:@"Can’t save the Coupon to favorite, Check your Internet connection."
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];

        [message performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
    }
    else if ( status == ReachableViaWiFi )
    {
        [self postCouponFav:idCoupon]; // Save the Coupon to Favorites
        [couponsCell.saveFav setEnabled:NO]; // Set diseable the button


    }
    else if ( status == ReachableViaWWAN )
    {
        [self postCouponFav:idCoupon];
        [couponsCell.saveFav setEnabled:NO];

    }

}

解決策は簡単かもしれませんが、iOS開発を学んでいます。助けてくれてありがとう。

4

1 に答える 1

0

返されるセルはセルの新しいインスタンスであり、表示されるセルではないため、デキューは使用できません。

ボタンの状態を変更するには双方向です。

  • (IBACTION) メソッドをコントローラ クラスではなくカスタム セル クラスにトランスポートし、レガシ コードをリリースします。CustomCell とコントローラーの間でデータを更新する必要がある場合は、デリゲートを作成して呼び出します。

  • 2番目の方法は、提示されたウェル状態に必要な値を設定した後、UITableViewのセルをリロードすることです

于 2013-09-02T17:35:57.533 に答える