Wednesday 15 September 2010

ios - Cannot access tableview cell UISearchBarController -


I have a custom UITableView cell, it has a custom button that shows a check box which is a check and uncheck Can be taped to show the image. It works correctly, but when filtering starts, UISearchBarController starts tapping my custom buttons inside a cell, so that the image is not updated properly. What results are shown in a different table view? The methods of updating cells are all called, but the image does not change

What is more complex: .. Cell Scroll out and Scene Out of View causes the cell to display correctly

  #define MAINLABEL_TAG 1 #define SECONDLABEL_TAG 2 #define CHECKBOX_TAG 3 - (UITableViewCell *) tableView: (UITableView *) TableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {static NSString * CellIdentifier = @ "cell"; UILBL * Main Label, * Second Label; UIButton * button = [UIButtonTypeCustom] with UIButton Button; PDFFile * newPDF = [_pdfDocumentFiltered.pdfFileListObjectAttexX: indexpath.ro]; // calculation label size GLfloat heightOfName = [TextSize computeHeightWithBoldFont: newPDF.documentTitle andViewWidth: 250 andFontSize: 18]; CGFloat heightOfDescription = [TextSize computeHeight: newPDF.description andViewWidth: 250 andFontSize: 16]; UITableViewCell * cell = [tableview] dequeueReusableCellWithIdentifier: CellIdentifier]; If (cell == blue) {cell = [[UITABLE DOCKEY alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; Cell.accessoryType = UITableViewCellAccessoryNone; // set main label attributes of mainLabel = [[UILabel alloc] initWithFrame: CGRectMake (60.0, 5.0, 250.0, heightOfName)]; MainLabel.tag = MAINLABEL_TAG; MainLabel.font = [UIFont boldSystemFontOfSize: 18.0]; MainLabel.textAlignment = UITextAlignmentLeft; MainLabel.textColor = [UIColor blackColor]; MainLabel.autoresizingMask = UIViewAutoresizing non; MainLabel.numberOfLines = 9; MainLabel.lineBreakMode = UILineBreakModeWordWrap; [Add cell contentviewSubview: Mainlabel]; // set second label attributes secondLabel = [[UILabel alloc] initWithFrame: CGRectMake (60.0, heightOfName + 10, 250.0, heightOfDescription)]; SecondLabel.tag = SECONDLABEL_TAG; SecondLabel.font = [UIFont systemFontOfSize: 16.0]; SecondLabel.textAlignment = UITextAlignmentLeft; SecondLabel.textcolor = [UIColor darkGrayColor]; Second label. Mask Mask = UIViewAutoresizingNone; SecondLabel.numberOfLines = 20; SecondLabel.lineBreakMode = UILineBreakModeWordWrap; [Add Cell.contentView SUBview: secondLabel]; [Button Set Frame: CGRactack (5.0, 0.0, 52.0, heightoff + height description +15)]; [Button set tag: CHECKBOX_TAG]; [Button addTarget: Self-action: @Selector (check uncheck :) Control events: UI Control Event Touchup Inside]; [Cell.contentView addSubview: buttons]; } Else {mainLabel = (UILabel *) [cell.contentViewViewTag: MAINLABEL_TAG]; [Main label setframe: CGRactack (60.0, 0.0, 250.0, heightOphName)]; Second label (= UILabel *) [cell.contentView view: SECONDLABEL_TAG]; [Second Label Setframe: CGRactMake (60.0, heightphone + 10, 250.0, heightup description)]; Button = (UIButton *) [cell.contentView view: CHECKBOX_TAG]; [Button Set Frame: CGRactack (5.0, 0.0, 52.0, heightoff + height description +15)]; } MainLabel.text = newPDF.documentTitle; SecondLabel.text = newPDF.description; If ([newPDF.check boolValue] == Yes) {NSLog ("Updating image to i% i", indexpath.ro); [Set button image: [UIImage imageNamed: @ "button check"] forState: UIControlStateNormal]; } Other {nslog (@ "image is not being updated"); [Set button image: [UIImage imageNamed: @ "uncheck button"] forState: UIControlStateNormal]; } Cell.tag = indexPath.row; Return cell; } - (IBAction) Check uncheck: (ID) sender {UIButton * sendingButton = (UIButton *) sender; UITableViewCell * cell = (UITableViewCell *) [[Send Baton Supervision] Supervision]; PDFFile * newPDF = [_pdfDocumentFiltered.pdfFileListObjectAttacks: cell.tag]; [New PDF set check: [NSNumber number whitblow:! [Npdf. Check ball value]]]; [Automatic reload data]; }    

You should not have cell tags, but you should tag the button correctly .

  [button setTag: indexPath.row]; // tag it properly = (UIButton *) [cell.contentViewViewTag: indexPath.row]; // Check it properly in the IBAction  
  - Check (IBAction) check: (ID) Sender {UIButton * sendingButton = (UIButton *) Sender; PDFFile * newPDF = [_pdfDocumentFiltered.pdfFileListObjectAttex: Sending buttonTags]; [New PDF set check: [NSNumber number whitblow:! [Npdf. Check ball value]]]; [Automatic reload data]; }    

No comments:

Post a Comment