Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to clear previous view when loading new detail view when a row is clicked in UITableView - iOS4
    text
    copied!<p>I need to display a detailed view controller with multiple labels when a row in a table view is clicked. The labels I am displaying are of dynamic height based on the content, which is being read from the iPhone's internal calendar. I have been able to implement the loading of detail views based on which row in the table view has been selected. My issue is that the previous detail view does not get cleared up when a new row is clicked. Especially in the case when my previous detail view had longer labels and the new detail view has shorter labels, I can see the content of the previous labels below the new one. How can I clear up the entire Detail View controller before reloading it with the new row's data. Following is the code I am using:</p> <p><b>RootViewController.m</b> </p> <pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (mdController == nil) { MtgDetailController *aController = [[MtgDetailController alloc] initWithNibName:@"MtgDetailController" bundle:nil]; self.mdController = aController; [aController release]; } self.mdController.mtgIndex = indexPath.row; // mdController.mtgIndex = indexPath.row; // [mdController setMtgIndex:indexPath.row]; // NSInteger temp = indexPath.row; UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@"Select an Option" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Open Meeting", @"Dial into meeting", nil]; [action showInView:self.parentViewController.view]; [action release]; } </code></pre> <p><b>MtgDetailController.m (This is the Detail View Controller)</b></p> <pre><code>-(void) viewDidAppear:(BOOL)animated { // [self reloadInputViews]; Smart_MeetingAppDelegate *myDelegate = (Smart_MeetingAppDelegate *)[[UIApplication sharedApplication]delegate]; CGRect scrollViewFrame = CGRectMake(0, 0, 320, 460); NSString *title = [myDelegate.titles objectAtIndex:self.mtgIndex]; NSString *mtg_time = [myDelegate.mtg_times objectAtIndex:self.mtgIndex]; NSString *loc = @"Conf Room 123"; // detail = @"test mtg test mtg. Dial number: 3334445555, (333)444-5555, 333-333-5555. ID: 4455333344, Password: 6576567"; detail = [myDelegate.detail_array objectAtIndex:self.mtgIndex]; NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:@"\\b[0-9]+(\\-)?(\\))?(\\.)?(\\s)?([0-9]+)?(\\-)?(\\.)?(\\s)?([0-9]+)?(\\-)?(\\.)?(\\s)?([0-9]+)?\\b" options:NSRegularExpressionCaseInsensitive error:nil]; NSArray* matches = [regex matchesInString:detail options:0 range:NSMakeRange(0, [detail length])]; [regex release]; unichar chr[1] = {'\n'}; NSString *singleCR = [NSString stringWithCharacters:(const unichar *)chr length:1]; NSString *titleRow = [NSString stringWithFormat:@"%@ %@ %@", title, singleCR, mtg_time]; NSMutableAttributedString *attrTitle = [NSMutableAttributedString attributedStringWithString:titleRow]; [attrTitle setFont:[UIFont systemFontOfSize:18] range:[titleRow rangeOfString:title]]; [attrTitle setFont:[UIFont systemFontOfSize:16] range:[titleRow rangeOfString:mtg_time]]; NSMutableAttributedString *attrLoc = [NSMutableAttributedString attributedStringWithString:loc]; NSMutableAttributedString *attrDetail = [NSMutableAttributedString attributedStringWithString:detail]; [attrDetail setFont:[UIFont systemFontOfSize:16]]; CGSize suggestedSize = [attrTitle sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)]; CGRect frame1 = CGRectMake(10, 15, 300, suggestedSize.height); OHAttributedLabel *lblTitle = [[OHAttributedLabel alloc] initWithFrame:frame1]; lblTitle.numberOfLines = 0; CGSize size2 = [attrLoc sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)]; CGRect frame2 = CGRectMake(10, suggestedSize.height+15+5, 300, size2.height); OHAttributedLabel *lblLocation = [[OHAttributedLabel alloc] initWithFrame:frame2]; CGFloat temp = size2.height+suggestedSize.height; CGSize size3 = [attrDetail sizeConstrainedToSize:CGSizeMake(300, FLT_MAX)]; CGRect frame3 = CGRectMake(10, temp+15+5, 300, size3.height); OHAttributedLabel *lblDescription = [[OHAttributedLabel alloc] initWithFrame:frame3]; lblDescription.numberOfLines = 0; lblTitle.attributedText = attrTitle; lblLocation.attributedText = attrLoc; lblDescription.attributedText = attrDetail; for (NSTextCheckingResult *m in matches) { NSString *num = [detail substringWithRange:m.range]; NSRange linkRange = [detail rangeOfString:num]; [lblDescription addCustomLink:[NSURL URLWithString:@"user://certa"] inRange:linkRange]; } lblDescription.delegate = self; [self.view addSubview:lblTitle]; [self.view addSubview:lblDescription]; [self.view addSubview:lblLocation]; [lblTitle release]; [lblLocation release]; [lblDescription release]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload