Wrox Programmer Forums
|
BOOK: Beginning iOS 5 Application Development
This is the forum to discuss the Wrox book Beginning iOS 5 Application Development by Wei-Meng Lee; ISBN: 978-1-1181-4425-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS 5 Application Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2012, 03:52 PM
Registered User
 
Join Date: Mar 2012
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 8 - Table View

I could get the code to work and run successfully but i get this warning to this line
Code:
//—-fired when the user taps on the searchbar—-
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {    
    isSearchOn = YES;
    canSelectRow = YES;
    
    if (searchBar.text.length>0){Local declaration of 'searchBar' hides instance variable
        self.tableView.scrollEnabled = YES;  
    } else {
        self.tableView.scrollEnabled = NO;
    }
    
    //—-add the Done button at the top—-
    self.navigationItem.rightBarButtonItem = 
    [[[UIBarButtonItem alloc] 
      initWithBarButtonSystemItem:UIBarButtonSystemItemDone
      target:self  
      action:@selector(doneSearching:)]
     autorelease];
}

This goes to the downloaded code from the author as well.

Secondly, the author showed how we could link the table to another view using
Code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSString *message;    
    if (isSearchOn && [searchResult count]>0) { 
        message = [[NSString alloc] initWithFormat:@"You have selected %@", 
                   [searchResult objectAtIndex:indexPath.row]];
    } else {
        NSString *year = [self.years objectAtIndex:[indexPath section]];
        NSArray *movieSection = [self.movieTitles objectForKey:year];
        NSString *movieTitle = [movieSection objectAtIndex:[indexPath row]];    
        message = [[NSString alloc] initWithFormat:@"You have selected %@", movieTitle];
    }

    
    if (!self.detailViewController) {
        self.detailViewController = [[[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil] autorelease];
    }
        
    //—-set the movie selected in the method of the
    // MovieDetailsViewController—-//
    self.detailViewController.detailItem = [message autorelease];
    
    [self.navigationController 
     pushViewController:self.detailViewController 
     animated:YES];
}
How can i link it to another view with a scrollview rather than text message. As in each link has its own scroll view.
 
Old March 15th, 2012, 11:20 PM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

There is an instance variable UISearchBar *searchBar. It is also an argument in the delegate method - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

This will not cause a problem in the method as implemented, but it is best to avoid having arguments to methods that are the same as ivars. The current practice in header files of have @property declarations only and not separate variable declarations is a way to avoid this. Note how in the RootViewController.h file the DetailViewController is declared as a property only and how its accessor is constructed in the @synthesize. This approach avoids the potential conflict between ivars and method arguments and promotes correct memory management by encouraging the use of accessors when setting ivars. It could be applied to the UISearchBar as follows
1. Eliminate declaration of the UISearchBar *searchBar; between the {}
2. add the IBOutlet macro to the @property as follows:
@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;

3. in the .m file change the @synthesize to
@synthesize searchBar = _searchBar;

4. Change all occasions where the ivar "searchBar" is used to self.searchBar

Now the delegate method signature can be used as written.

It is a good idea to get in the habit of using the @property declarations following the practice demonstrated in the templates. This practice strongly discourages direct setting of ivars, since direct setting can cause problems with memory leaks.

Concerning part 2 of your question:

A UIScrollView can be added to the DetailViewController either in the .xib or programmatically. The detailItem is simply a placeholder to show how an object can be passed in.


Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 8 - Table View (Sorting of Arrays in Table View) teamstar BOOK: Beginning iOS 5 Application Development 1 March 15th, 2012 10:30 PM
Table frame view RockBal XSLT 3 April 5th, 2011 01:32 AM
updating the table from the list view columns Yasho VB Databases Basics 2 July 31st, 2007 02:06 AM
view table using asp code ernafarizan Classic ASP Basics 4 March 8th, 2005 07:46 PM
Table View and DB Changes rander3328 SQL Server 2000 3 September 16th, 2004 11:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.