【发布时间】:2013-09-02 06:33:26
【问题描述】:
我有一个自定义单元格,它使用包含以下组件的情节提要:
1 UIImage 2个UILabel 4 个 UI 按钮
一个按钮允许用户将优惠券保存为收藏夹,我想在用户保存优惠券后将此按钮设置为禁用,我尝试为自定义单元格类中的按钮添加一个 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 开发。提前感谢您的帮助。
【问题讨论】:
-
请更改您的主题以使用混合大小写(不要大喊大叫)并将其更改为反映您的问题的正确标题。
-
如果您在 AddFavorite 方法中放置一个断点,执行是否会停止?
-
对不起,我是stackoverflow的新手,我已经改了标题...
-
@tdelepine 是的,它是...优惠券已保存为收藏,但不会将状态更改为禁用。
标签: ios objective-c