我有一个自定义单元格,它使用具有以下组件的情节提要:
1 UIImage 2 UILabels 4 UIbuttons
一个按钮允许用户将优惠券保存为收藏夹,我想在用户保存优惠券后将此按钮设置为禁用,我尝试为自定义单元格类中的按钮添加 IBOutlet 但它不起作用而且我没有得到任何错误。我怎样才能做到这一点?有人可以帮助我吗?
编码:
优惠券Cell.h
@property (nonatomic, strong) IBOutlet UIButton *saveFav;
优惠券Cell.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 开发。提前感谢您对我的帮助。