UITableView addSubview and table lines - iphone

I'm trying to add a custom view to an UITableView created with code from an UITableViewController. This view is a HUD window with a message (MBProgressHUD)
So I have a method reload() called from the overridden initWithStyle() method and from the refresh button of the table:
- (void) reload {
HUD = [[MBProgressHUD alloc] initWithView:self.tableView];
[self.view addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Downloading";
[HUD showWhileExecuting:#selector(reloadWithHUD) onTarget:self withObject:nil animated:YES];
}
The first time, the HUD appears behind the table lines. Once loaded, when I press reload button, the view shows as expected. The initWithStyle() method (with some code removed for clarity) is:
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization.
self.title = NSLocalizedString...
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle ... action:#selector(reload)];
self.navigationItem.rightBarButtonItem = button;
[button autorelease];
[self reload];
}
return self;
}
I've tried changing the HUD view with a simple UILabel, with the same result.
I also changed the code to call reload() from viewDidLoad(), but doesn't work either. How can I resolve this issue? Thank you very much.
EDIT : to clarify this, here is a possible solution to this problem. Many thanks to Bill Brasky for his help:
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[[[UIApplication sharedApplication] keyWindow] addSubview:HUD];

Here is what I'm doing in my app with an almost identical application.
You need to add it to the main view WINDOW, not the tableView.
HUD = [[MBProgressHUD alloc] initWithView:self.view.window];
[self.view.window addSubView:HUD];

My project is based on IOS 7
This helps me
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Related

Bring Tab bar back after using navigation bar

I have an app that based on Tab Bar combined with navigation bar.
In the navigation bar i have a button that takes me to another page which I want to hide the tab bar. When i trying to back to the main view through a button (Not back bar button, regular one) i can't bring the Tab Bar back.
I did try : xxxxx.hidesBottomBarWhenPushed =NO;
Here is some of my code:
In main view:
In viewDidLoad:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:buttonTitle
style:UIBarButtonItemStylePlain
target:self
action:#selector(goToCreateEvent)];
-(void)goToCreateEvent{
UIViewController *targetViewController;
NSString *viewControllerName = #"CreateAnEventViewController";
targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
targetViewController.hidesBottomBarWhenPushed =YES; //Hides the tab bar
[self.navigationController pushViewController:targetViewController animated:YES];
}
In the other view:
-(IBAction)save:(id)sender
{
[summary resignFirstResponder];
[agenda resignFirstResponder];
FeedViewController *aboutViewCont = [[FeedViewController alloc] init];
aboutViewCont.hidesBottomBarWhenPushed =NO; //trying to bring back the tab bar
[[self navigationController] pushViewController:aboutViewCont animated:NO];
}
Thanks!
Yossi
This simply solve it:
[[self navigationController] popToRootViewControllerAnimated:YES];
in viewWillAppear: method of FeedViewController set hidesBottomBarWhenPushed to NO like bellow..
-(void)viewWillAppear:(BOOL)animated{
self.hidesBottomBarWhenPushed = NO;
}
UPDATE: Try out this one also..
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
CGRect r = self.tabBarController.view.frame;
r.size.height +=self.tabBarController.tabbar.frame.size.height;
self.tabBarController.view.frame = r;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.tabBarController.view.frame = CGRectMake(0, 0, 320, 480); //for iPhone portrait
}
use this above methods in your FeedViewController class and also just comment this bellow line from your code..
targetViewController.hidesBottomBarWhenPushed =YES;//comment this..

Hide a UITableView of a UIScrollview on a button click in iPhone

I have a UITableView with some data in -(void)ViewDidLoad. So it appears accordingly. But when I click a button then my tableview should be hidden and I should load a UIlabel with some text.
But for me on button click empty tableview with some rows is loading. I should avoid it. How can I do it?
Here is my code
-(void)ViewDidLoad {
tableView=[[UITableView alloc]initWithFrame:CGRectMake(0,380,320,200) style:UITableViewStylePlain];
tableView.delegate = self;
tableView.dataSource = self;
[self.view addSubview:tableView];
}
-(void)DatePickerDoneClick:(id)sender {
[tableview setHidden:YES];
displayError =[[UILabel alloc]init];
[displaytError setFrame:CGRectMake(20,400,320,100)];
displayError.textAlignment=UITextAlignmentLeft;
displayError.backgroundColor=[UIColor clearColor];
displayError.text=[NSString stringWithFormat:#"Not found"];
[self.view addSubview:displayError];
}
Could not get where I'm going wrong?
To hide Table View you can use
myTableView.hidden = YES;
or
[mtTableView setHidden:YES];
Hope this will help you out.
if tableview.hidden = YES; is not doing the job
try the next code:
[self.tableview removeFromSuperView];

MBProgressHUD call from ViewDidLoad

I call my rss parser from MBProgressHUD and at the moment it's in viewdidappear and it works, however I want it in viewdidload so when I go back it doesn't reload it - however when I move it in to viewdidload it runs the process but not the MBProgressHUD.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Results";
HUD = [[MBProgressHUD alloc] initWithWindow:[UIApplication sharedApplication].keyWindow];
[self.view.window addSubview:HUD];
HUD.delegate = self;
HUD.labelText = #"Loading";
HUD.detailsLabelText = #"updating data";
//Show the HUD while the provided method executes in a new thread
[HUD showWhileExecuting:#selector(loadResults) onTarget:self withObject:nil animated:YES];
}
Any ideas?
Thanks, Tom
In viewDidLoad method, the self.view will be loaded without its superview and window. For Example, self.view.superview will be loaded in viewWillAppear method, then self.view.window will be loaded in viewDidAppear method. That's why the [self.view.window addSubview:HUD] won't be happened in viewDidLoad, but the [self.view addSubview:HUD] works.
Try below code, its working fine at my end.
- (void)viewDidLoad {
[super viewDidLoad];
HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.labelText = #"Loading";
HUD.detailsLabelText = #"updating data";
}

How to dismiss pop over view in content view?

see the screen shot is clear to understand what I mean
you can see I add a navigationItem in my pop view
I wish I can dismiss the pop view
But it seems only tab the cell under the pop view
The pop view will dismiss,I try to add this method
[self.view removeFromSuperview];
It only remove the table view , the pop view frame is still there ,only without the content view
Any reply will be helpful : )
Thanks
Webber
/******EDIT******/
I use WEPopoverView into my project
And this is the code I create the pop view when I select the table view
if (indexPath.row==2) {
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
if (self.popoverController) {
[self.popoverController dismissPopoverAnimated:YES];
self.popoverController = nil;
}
else {
self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:navPopView] autorelease];
CGRect frame = [tableView cellForRowAtIndexPath:indexPath].frame;
[self.popoverController presentPopoverFromRect:frame
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp
animated:YES];
}
}
/******EDIT2******/
I try to add Done button when I create the pop view
here is the code , But it only appear a navigation , no Done button
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
navPopView.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(hidePopView)];
While you add the popup view, set tag to that popupView and then, add them as subview,
then use:
for (UIView *tempView in [self.view subviews]) {
if ([tempView tag]==urTag) {
[tempView removeFromSuperview];
}
}
This retrieves all the subviews and then remove only your popupview
I think that simply releasing your self.popoverController will do the dismiss properly, including all the superviews.
You can also have a look at the dealloc method in WEPopoverController to see which views are involved and need to be removed:
[self dismissPopoverAnimated:NO];
[contentViewController release];
[containerViewProperties release];
[passthroughViews release];
Anyway, the only advantage I see is the possibility of calling dismissPopoverAnimated with YES.
Hope this helps.
EDIT:
How can you connect your done button to your controller?
Make your button accessible through a read-only property of DaysOfWeek; then in your controller, when you create DaysOfWeek, do:
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
[propView.doneButton addTarget:self action:#selector(fullyDismissPopover) forControlEvents:UIControlEventTouchUpInside];
In fullyDismissPopover, you call release or call the sequence of functions highlighted above (but release would be better, I think).
DaysOfWeek *popView = [[DaysOfWeek alloc]init];
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
[doneButton addTarget:self action:#selector(hidePopView) forControlEvents:UIControlEventTouchUpInside];
popView.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:doneButton] autorelease];
UINavigationController *navPopView = [[UINavigationController alloc] initWithRootViewController:popView];
This also can figure out the problem !

iPhone - Navigation bar Back button item is not responding

I have a fullscreen modalView called like this:
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:#"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
Then from this modalView I push another view :
MyController *nextWindow = [[[MyController alloc] initWithNibName:#"tmp" bundle:nil] autorelease];
[self.navigationController pushViewController:nextWindow animated:YES];
In this new controller, I have this viewDidLoad :
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Borders";
self.navigationController.navigationBarHidden = NO;
}
The leftBarButtonItem is not active, I mean touching it does not highlight it nor does it go back to the previous view.
My views are displayed fullScreen, with [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; called at the application initialisation.
The navigationBar frame is 0,0,320,44.
The navigationBar superview frame is 0,0,320,480.
The viewController view frame is 0,0,320,436.
I've tried to call in viewDidLoad self.navigationController.navigationBar.userInteractionEnabled = YES; and self.navigationItem.leftBarButtonItem.enabled = YES; without effect.
What happens?
EDIT :
My self.navigationController.navigationItem.backBarButtonItem is NIL.
self.navigationController.navigationItem is not NIL
Whenever this sort of unresponsiveness happens to me, it is always because of framing issues. i.e. the superview of the NavigationController is smaller than the NavigationController's view. I know you say that everything is set to full screen, but I would verify that everything is actually full screen by turning "clipsSubviews" on for each view in the hierarchy.
I just had this issue, I'm not sure why this works, but instead of doing:
UIBarButtonItem *backButton =
[[[UIBarButtonItem alloc] initWithTitle:#"Back"
style: UIBarButtonItemStyleBordered
target:nil
action:nil] autorelease];
self.navigationItem.leftBarButtonItem = backButton;
I replaced the second line with
self.navigationController.navigationItem.leftBarButtonItem = backButton;
That works for me.
I found the solution.
The problem was that the first view was called from the overlay, and not from the picker.
Keeping a reference to the Picker into the overlay, and calling the view from it solves the problem:
From the overlay:
[self.picker presentModalViewController:navController animated:YES];
works
instead of:
[self presentModalViewController:navController animated:YES];