पर रीडाव नहीं करेगा I कक्षा UIButton
, UIImage
, और दो UILabels
के साथ एक कस्टम UITableViewCell
कक्षा बनाई गई है। बटन और छवि एक दूसरे के शीर्ष पर ओवरलेड हैं, और एक समय में केवल एक ही प्रदर्शित होता है। अपेक्षित व्यवहार आप बटन पर स्पर्श करते हैं, बटन गायब हो जाता है, और यह छवि प्रदर्शित करता है। UITableViewCells
पुन: उपयोग किए जाने के लिए सेट हैं।कस्टम UITableViewCell setNeedsDisplay
कंस्ट्रक्टर::
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
unheartButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
unheartButton.backgroundColor = [UIColor clearColor];
unheartButton.frame = CGRectMake(10, 13, 20, 18);
[unheartButton addTarget:self action:@selector(onButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[unheartButton setBackgroundImage:[UIImage imageNamed:@"redheart.png"] forState:UIControlStateNormal];
imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(12, 13, 16, 16);
NSMutableArray *array = [[NSMutableArray alloc] init];
for (int ndx = 1; ndx < 13; ndx++) {
[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"icon-loading-%d (dragged).tiff", ndx]]];
}
imageView.animationImages = array;
imageView.animationDuration = 1;
[array release];
[self.contentView addSubview:imageView];
[self.contentView addSubview:unheartButton];
return self;
}
}
- (void) setModel:(MyModel *)myModel {
model = myModel;
if (model.hideImage) {
imageView.hidden = YES;
unheartButton.hidden = NO;
else {
imageView.hidden = NO;
unheartButton.hidden = YES;
}
}
बटन क्लिक करें:
- (IBAction) onButtonClick: (id) sender {
model.hideImage = NO;
unheartButton.hidden = YES;
imageView.hidden = NO;
[imageView startAnimating];
[self setNeedsDisplay];
[self.contentView setNeedsDisplay];
[self.unheartButton setNeedsDisplay];
[self.imageView setNeedsDisplay];
}
मैं सब कुछ पर setNeedsDisplay
फोन कर रहा हूँ, लेकिन कुछ नहीं हो रहा है यहाँ मेरी कोड है। अगर मैं स्क्रीन को स्क्रॉल करता हूं और बैक अप करता हूं, तो बटन छिपा हुआ है और अब लोडिंग आइकन दिखाया गया है, लेकिन यह स्क्रॉल के बाद ही होता है। मुझे यकीन नहीं है कि सेल को पुन: पेश करने के लिए मुझे क्या करना है।
मैं NSIndexPath जोड़ सकते हैं और सेल के लिए असाइन करें,: इस पोस्ट में अधिक जानकारी के लिए देखें [NSArray arrayWithObject: currentCell.indexPath] withRowAnimation: UITableViewRowAnimationNone]; –