removing uisearchdisplay controller

This commit is contained in:
Roy Yang 2012-07-31 15:17:51 -07:00
parent bc997cffa1
commit 8275e61c66
6 changed files with 104 additions and 86 deletions

View file

@ -11,21 +11,18 @@
@class NewsBlurAppDelegate;
@class ASIHTTPRequest;
@interface FriendsListViewController : UITableViewController <UISearchBarDelegate, UISearchDisplayDelegate> {
@interface FriendsListViewController : UITableViewController <UISearchBarDelegate> {
NewsBlurAppDelegate *appDelegate;
UISearchBar *searchBar;
UISearchDisplayController *searchDisplayController;
UISearchBar *friendSearchBar;
UITableView *friendsTable;
NSArray *suggestedUserProfiles;
NSArray *userProfiles;
NSArray *userProfileIds;
}
@property (nonatomic) IBOutlet NewsBlurAppDelegate *appDelegate;
@property (nonatomic) IBOutlet UISearchBar *searchBar;
@property (nonatomic) IBOutlet UISearchDisplayController *searchDisplayController;
@property (nonatomic, retain) UISearchBar *friendSearchBar;
@property (nonatomic) NSArray *userProfiles;
@property (nonatomic) NSArray *suggestedUserProfiles;

View file

@ -18,13 +18,19 @@
}
@end
@interface FriendsListViewController()
@property (readwrite) BOOL inSearch_;
@end
@implementation FriendsListViewController
@synthesize appDelegate;
@synthesize searchBar;
@synthesize searchDisplayController;
@synthesize friendSearchBar;
@synthesize suggestedUserProfiles;
@synthesize userProfiles;
@synthesize inSearch_;
- (id)initWithStyle:(UITableViewStyle)style
{
@ -56,22 +62,17 @@
UISearchBar *newSearchBar = [[UISearchBar alloc] init];
UISearchDisplayController *newSearchBarController = [[UISearchDisplayController alloc] initWithSearchBar:newSearchBar contentsController:self];
self.searchDisplayController = newSearchBarController;
self.searchDisplayController.searchResultsDelegate = self;
self.searchDisplayController.searchResultsDataSource = self;
self.searchDisplayController.delegate = self;
newSearchBar.frame = CGRectMake(0,0,0,38);
newSearchBar.placeholder = @"Search by username or email";
self.searchBar = newSearchBar;
newSearchBar.delegate = self;
self.friendSearchBar = newSearchBar;
self.tableView.tableHeaderView = newSearchBar;
}
- (void)viewDidUnload
{
[self setSearchBar:nil];
[self setSearchDisplayController:nil];
[self setFriendSearchBar:nil];
[self setSuggestedUserProfiles:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
@ -90,23 +91,25 @@
[appDelegate.findFriendsNavigationController dismissModalViewControllerAnimated:YES];
}
#pragma mark - UISearchDisplayController delegate methods
#pragma mark - UISearchBar delegate methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
if (searchString.length == 0) {
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
if (searchText.length == 0) {
self.userProfiles = nil;
self.inSearch_ = NO;
[self.tableView reloadData];
} else {
self.inSearch_ = YES;
[self loadFriendsList:searchText];
}
[self loadFriendsList:searchString];
return NO;
}
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchScope:(NSInteger)searchOption
{
return NO;
- (void)searchBarTextDidEndEditing:(UISearchBar *)theSearchBar {
[theSearchBar resignFirstResponder];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}
- (void)loadFriendsList:(NSString *)query {
@ -152,24 +155,27 @@ shouldReloadTableForSearchScope:(NSInteger)searchOption
}
- (void)requestFinished:(ASIHTTPRequest *)request {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSString *responseString = [request responseString];
NSData *responseData= [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *results = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
// int statusCode = [request responseStatusCode];
int code = [[results valueForKey:@"code"] intValue];
if (code == -1) {
return;
if (self.inSearch_) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSString *responseString = [request responseString];
NSData *responseData= [responseString dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSDictionary *results = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
// int statusCode = [request responseStatusCode];
int code = [[results valueForKey:@"code"] intValue];
if (code == -1) {
return;
}
self.userProfiles = [results objectForKey:@"profiles"];
[self.tableView reloadData];
}
self.userProfiles = [results objectForKey:@"profiles"];
[self.searchDisplayController.searchResultsTableView reloadData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
@ -185,8 +191,7 @@ shouldReloadTableForSearchScope:(NSInteger)searchOption
#pragma mark - Table view data source
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if ([tableView
isEqual:self.searchDisplayController.searchResultsTableView]){
if (self.inSearch_){
return 0;
} else {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
@ -199,7 +204,6 @@ shouldReloadTableForSearchScope:(NSInteger)searchOption
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
int headerLabelHeight, folderImageViewY;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
@ -283,15 +287,6 @@ viewForHeaderInSection:(NSInteger)section {
}
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if ([tableView
isEqual:self.searchDisplayController.searchResultsTableView]){
return nil;
} else {
return @"People To Follow";
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect vb = self.view.bounds;
@ -302,46 +297,48 @@ viewForHeaderInSection:(NSInteger)section {
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
reuseIdentifier:nil];
} else {
[[[cell contentView] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)];
}
ProfileBadge *badge = [[ProfileBadge alloc] init];
badge.frame = CGRectMake(5, 5, vb.size.width - 35, self.view.frame.size.height);
if ([tableView isEqual:self.searchDisplayController.searchResultsTableView]){
if (self.inSearch_){
[badge refreshWithProfile:[self.userProfiles objectAtIndex:indexPath.row] showStats:NO withWidth:vb.size.width - 35 - 10];
[cell.contentView addSubview:badge];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
int userCount = [self.suggestedUserProfiles count];
if (!userCount) {
if (indexPath.row == 1) {
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, vb.size.width, 140)];
[cell.contentView addSubview:myLabel];
myLabel.text = @"Nobody left to recommend. Good job!";
myLabel.textColor = UIColorFromRGB(0x7a7a7a);
// add a NO FRIENDS TO SUGGEST message on either the first or second row depending on iphone/ipad
int row = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
row = 1;
}
if (indexPath.row == row) {
UILabel *msg = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, vb.size.width, 140)];
[cell.contentView addSubview:msg];
msg.text = @"Nobody left to recommend. Good job!";
msg.textColor = UIColorFromRGB(0x7a7a7a);
if (vb.size.width > 320) {
myLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size: 20.0];
msg.font = [UIFont fontWithName:@"Helvetica-Bold" size: 20.0];
} else {
myLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size: 14.0];
msg.font = [UIFont fontWithName:@"Helvetica-Bold" size: 14.0];
}
myLabel.textAlignment = UITextAlignmentCenter;
msg.textAlignment = UITextAlignmentCenter;
}
} else {
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
[badge refreshWithProfile:[self.suggestedUserProfiles objectAtIndex:indexPath.row] showStats:NO withWidth:vb.size.width - 35 - 10];
[cell.contentView addSubview:badge];
}
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
@ -349,9 +346,10 @@ viewForHeaderInSection:(NSInteger)section {
NSInteger currentRow = indexPath.row;
int row = currentRow;
appDelegate.activeUserProfileId = [[self.userProfiles objectAtIndex:row] objectForKey:@"user_id"];
[self.searchBar resignFirstResponder];
[self.friendSearchBar resignFirstResponder];
NSLog(@"appDelegate.findFriendsNavigationController is %@", appDelegate.findFriendsNavigationController);
[appDelegate.findFriendsNavigationController pushViewController:appDelegate.userProfileViewController animated:YES];
[appDelegate.userProfileViewController getUserProfile];
}
@end
@end

View file

@ -198,7 +198,7 @@
popoverController.delegate = self;
}
[popoverController setPopoverContentSize:CGSizeMake(200, 90)];
[popoverController setPopoverContentSize:CGSizeMake(200, 86)];
UIBarButtonItem *settingsButton = [[UIBarButtonItem alloc]
initWithCustomView:sender];
[popoverController presentPopoverFromBarButtonItem:settingsButton

View file

@ -206,16 +206,13 @@
}
- (void)showFindFriends {
FriendsListViewController *friendsBVC = [[FriendsListViewController alloc] initWithStyle:UITableViewStyleGrouped];
self.friendsListViewController = friendsBVC;
FriendsListViewController *friendsBVC = [[FriendsListViewController alloc] init];
UINavigationController *friendsNav = [[UINavigationController alloc] initWithRootViewController:friendsListViewController];
self.friendsListViewController = friendsBVC;
self.findFriendsNavigationController = friendsNav;
self.findFriendsNavigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.findFriendsNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[masterContainerViewController presentModalViewController:findFriendsNavigationController animated:YES];
@ -283,7 +280,6 @@
[feedsMenuViewController dismissModalViewControllerAnimated:NO];
[self.navigationController presentModalViewController:loginViewController animated:NO];
}
}
- (void)showFirstTimeUser {

View file

@ -432,10 +432,11 @@
if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) {
[self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
}
[self.popoverController setPopoverContentSize:CGSizeMake(200, 90)];
[self.popoverController setPopoverContentSize:CGSizeMake(200, 86)];
[self.popoverController presentPopoverFromBarButtonItem:self.navigationItem.rightBarButtonItem
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}

View file

@ -135,7 +135,16 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
<object class="IBUIViewController" id="1039547804">
<object class="IBUIViewController" id="824014421">
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
<int key="interfaceOrientation">1</int>
</object>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIHorizontal">NO</bool>
</object>
<object class="IBUIViewController" id="181086508">
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="IBUIInterfaceOrientation">1</int>
@ -303,10 +312,18 @@
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">friendsListViewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="1039547804"/>
<reference key="destination" ref="824014421"/>
</object>
<int key="connectionID">135</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">userProfileViewController</string>
<reference key="source" ref="664661524"/>
<reference key="destination" ref="181086508"/>
</object>
<int key="connectionID">142</int>
</object>
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">appDelegate</string>
@ -382,7 +399,7 @@
<object class="IBConnectionRecord">
<object class="IBCocoaTouchOutletConnection" key="connection">
<string key="label">appDelegate</string>
<reference key="source" ref="1039547804"/>
<reference key="source" ref="824014421"/>
<reference key="destination" ref="664661524"/>
</object>
<int key="connectionID">136</int>
@ -503,7 +520,12 @@
</object>
<object class="IBObjectRecord">
<int key="objectID">134</int>
<reference key="object" ref="1039547804"/>
<reference key="object" ref="824014421"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">141</int>
<reference key="object" ref="181086508"/>
<reference key="parent" ref="0"/>
</object>
</object>
@ -533,6 +555,8 @@
<string>131.IBPluginDependency</string>
<string>134.CustomClassName</string>
<string>134.IBPluginDependency</string>
<string>141.CustomClassName</string>
<string>141.IBPluginDependency</string>
<string>3.CustomClassName</string>
<string>3.IBPluginDependency</string>
<string>39.IBPluginDependency</string>
@ -568,6 +592,8 @@
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>FriendsListViewController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>UserProfileViewController</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>NewsBlurAppDelegate</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
@ -593,7 +619,7 @@
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">140</int>
<int key="maxID">142</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">