ViewController goes black when pushing it in UINavigationcontroller stack - ios

I have a UInavigationController stack. In the RootViewController i have button . When i click the button a new viewcontroller is pushed and UIDatePicker should be shown . the problem is when navigating to view controller the date picker is shown for 1 sec and then suddenly disappeared and the whole screen goes Black. Here is the code
//rootviewcontroller
- (IBAction)dateAction:(id)sender
{
self.another = [[AnotherViewController alloc]initWithButtonWithTag:self.dateButton.tag andDelegate:self];
[self.navigationController pushViewController:self.another animated:YES];
self.another.navigationItem.title = #"DateName";
}
//second viewcontroller
- (void)viewDidload
{
self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
[self.pickerView addTarget:self action:#selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
self.pickerView.datePickerMode = UIDatePickerModeDate;
self.pickerView.hidden = NO;
self.pickerView.date = [NSDate date];
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateStyle = NSDateFormatterLongStyle;
[self.view addSubview:self.pickerView];
}
A help would be appreciated

try this code…
first view controller
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *temp=[NSArray arrayWithObjects:#"button1" ,#"button2" ,#"button3",nil];
for (int i=0; i<=2; i++)
{
_likeBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[_likeBtn setFrame:CGRectMake(20+(i*80), 220, 102, 20 )];
[_likeBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[_likeBtn setTitle:[temp objectAtIndex:i] forState:UIControlStateNormal];
[_likeBtn addTarget:self action:#selector(action:) forControlEvents:UIControlEventTouchUpInside];
[_likeBtn setTag:i];
[self.view addSubview:_likeBtn];
}
// Do any additional setup after loading the view from its nib.
}
- (IBAction)action:(id)sender
{
UIButton *button=(UIButton *)sender;
NSLog(#"%d",button.tag);
secViewController *obj = [[secViewController alloc]init];
obj.tagValue=button.tag;
[self.navigationController pushViewController:obj animated:YES];
obj.navigationItem.title = #"DateName";
}
second view .h file
#property(nonatomic,assign) NSInteger *tagValue;
.m file
- (void)viewDidLoad
{
[super viewDidLoad];
NSInteger *tag=self.tagValue;
if (tag==0)
{
//tableView
NSLog(#"tableview");
}
else
{
//datepicker
NSLog(#"picker");
self.pickerView = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 250, 325, 300)];
[self.pickerView addTarget:self action:#selector(datePickerDidChangeDate:) forControlEvents:UIControlEventValueChanged];
self.pickerView.datePickerMode = UIDatePickerModeDate;
self.pickerView.hidden = NO;
self.pickerView.date = [NSDate date];
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateStyle = NSDateFormatterLongStyle;
[self.view addSubview:self.pickerView];
}
// Do any additional setup after loading the view from its nib.
}
-(void)datePickerDidChangeDate:(id)sender
{
NSLog(#"%#",self.pickerView.date);
}
let me know statisfied or not...

Related

SearchBar moves when active

I have a UIViewController with a SegmentedControl, UITableView and a UISearchController. The SegmentedControl is at the top of the main View with the tableView just beneath it. The searchController's searchBar is placed in the tableView.tableHeaderView and looks like this:
When the searchBar is tapped (made active) it moves down leaving a gap just above:
Also, if the searchBar is active and then the segmentedConrol is tapped (filtering the table data and reloading the tableView) then the tableView loads but with a gap at the top. (I have purposely set the searchBar to hidden when the 'Category' filter is selected.
If the segmentedControl 'Category' is selected when the searchBar is not active this is how it looks (and should look):
I need two things (I think they are related), 1) for the searchBar to NOT move when active and 2) for the searchBar to not be present when 'Category' is selected and for the tableView to have no gap at the top.
.h:
#interface ExhibitorViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchControllerDelegate, UISearchBarDelegate, UISearchResultsUpdating>
{
// DATA
NSMutableArray *arrayOfExhibitors;
NSMutableArray *arrayOfExhibitorsFiltered;
NSMutableArray *arrayOfCategories;
NSMutableArray *arrayOfCategoriesFiltered;
// VARS
int selectedSegment;
float searchBarHeight;
float tableViewY;
NSString *currentCategory;
CGRect tableViewStartRect;
// UI
UISegmentedControl *segmentedControl;
UIView *categorySelectedView;
UIView *headerView;
}
#property (nonatomic, strong) UITableView *tableView;
#property (nonatomic, strong) UISearchController *searchController;
#property (nonatomic, readonly) NSArray *searchResults;
#property (strong, nonatomic) NSString *sponsorsOnly;
#end
.m:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
if (selectedSegment == 0) {
self.searchController.searchBar.hidden = FALSE;
}
if (!_searchController.searchBar.superview) {
self.tableView.tableHeaderView = self.searchController.searchBar;
}
}
-(void)loadTableView
{
[self printStats:#"loadTableView START"];
searchBarHeight = self.searchController.searchBar.frame.size.height;
Settings *settingsInstance = [Settings new];
if(!_tableView) {
segmentedControl = [UISegmentedControl new];
segmentedControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:#"Exhibitor", #"Category", nil]];
[segmentedControl setFrame:CGRectMake(0, 0, self.view.frame.size.width, 35)];
segmentedControl.selectedSegmentIndex = 0;
[segmentedControl addTarget:self action:#selector(segmentedControlHasChangedValue) forControlEvents:UIControlEventValueChanged];
self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
self.searchController.hidesNavigationBarDuringPresentation = NO;
//self.definesPresentationContext = NO;
float tvX = self.view.frame.origin.x;
float tvY = self.view.frame.origin.y + segmentedControl.frame.size.height;
float tvWidth = self.view.frame.size.width;
float frameHeight = self.view.frame.size.height;
float tvHeight = self.view.frame.size.height - segmentedControl.frame.size.height;
tableViewStartRect = CGRectMake(tvX, tvY, tvWidth, tvHeight);
_tableView = [UITableView new];
_tableView = [[UITableView alloc] initWithFrame:tableViewStartRect];
//_tableView.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);
_tableView.separatorColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:segmentedControl];
[self.view addSubview:_tableView];
[_tableView setTag:1];
[_tableView setDataSource:self];
[_tableView setDelegate:self];
}
if (!categorySelectedView) {
float levelOneStart = (0);
categorySelectedView = [[UIView alloc] initWithFrame:CGRectMake(0, levelOneStart, self.view.frame.size.width, (screenHeight * 0.05))];
[categorySelectedView setBackgroundColor:[UIColor grayColor]];
[categorySelectedView setTag:4];
MyLabel *catSelectedLabel = [[MyLabel alloc] initWithFrame:categorySelectedView.frame];
[catSelectedLabel setFont:[UIFont systemFontOfSize:[settingsInstance getFontSizeFor:#"Label"]]];
[catSelectedLabel setTag:5];
[catSelectedLabel setBackgroundColor:[UIColor lightTextColor]];
[catSelectedLabel setTextColor:[UIColor darkGrayColor]];
UIButton *categoryBackButton = [[UIButton alloc] initWithFrame:CGRectMake((screenWidth * 0.6), levelOneStart, (screenWidth * 0.4), (screenHeight * 0.05))];
[categoryBackButton setTitle:#"^ Back ^" forState:UIControlStateNormal];
[categoryBackButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
[categoryBackButton addTarget:self action:#selector(resetTableViewCategories) forControlEvents:UIControlEventTouchUpInside];
[catSelectedLabel addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(resetTableViewCategories)]];
[categoryBackButton.titleLabel setFont:[UIFont systemFontOfSize:[settingsInstance getFontSizeFor:#"Label"]]];
[categorySelectedView addSubview:catSelectedLabel];
[categorySelectedView addSubview:categoryBackButton];
[categorySelectedView setHidden:TRUE];
}
if (!headerView) {
headerView = [[UIView alloc] initWithFrame:CGRectMake(0, (0), screenWidth, (searchBarHeight))];
[headerView addSubview:categorySelectedView];
[self.view addSubview:headerView];
[headerView setBackgroundColor:[UIColor purpleColor]];
[self.view sendSubviewToBack:headerView];
}
[self.view setTag:11];
tableViewY = _tableView.frame.origin.y;
[self printStats:#"loadTableView END"];
}
-(UISearchController*)searchController
{
if (!_searchController) {
_searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
_searchController.searchResultsUpdater = self;
_searchController.dimsBackgroundDuringPresentation = NO;
_searchController.searchBar.delegate = self;
[_searchController.searchBar sizeToFit];
}
return _searchController;
}
-(void)segmentedControlHasChangedValue
{
[self.searchController setActive:NO];
if ((segmentedControl.selectedSegmentIndex == 0)) {
selectedSegment = 0;
currentCategory = #"";
[self resetTableViewExhibitors];
[_tableView setContentOffset:CGPointMake(0, -1) animated:NO];
} else {
selectedSegment = 1;
[self resetTableViewCategories];
[_tableView setContentOffset:CGPointMake(0, -1) animated:NO];
//[_tableView setContentOffset:CGPointMake(0, 56) animated:NO];
[_tableView setTableFooterView:nil];
}
[_tableView reloadData];
}
I have tried changing the insets of various views and forcing a manual changes to the frames of various views (this is the closest thing to a fix but seems very hacky). What am I doing wrong?
Edit: Have also tried :
-(void)segmentedControlHasChangedValue
{
[self.searchController setActive:NO];
if ((segmentedControl.selectedSegmentIndex == 0)) {
selectedSegment = 0;
currentCategory = #"";
[self resetTableViewExhibitors];
[_tableView setContentOffset:CGPointMake(0, -1) animated:NO];
} else {
selectedSegment = 1;
[_searchController dismissViewControllerAnimated:NO completion^() {
[self resetTableViewCategories];
[_tableView setContentOffset:CGPointMake(0, -1) animated:NO];
[_tableView setTableFooterView:nil];
}];
}
[_tableView reloadData];
}
Because you use UISearchController so searchBar will always move when it actives. To avoid it, use UISearchBar. And when you use UISearchBar, it's easy to hide when you select Category tab

UITextField from enterBackground to enterForeground,app crash

custom UITextField: In the click TextField input,After the keyborad popup,enter the background to get enter foreground again,The app crash!
if you don't click TextField input,background or foreground conversion ,It is normal;Part of the code:
#implementatio BKSearchViewController
- (void)setNavgationView {
BKSearchBar *searchBar = [[BKSearchBar alloc] initWithFrame:CGRectMake(20, 27, kScreenWidth - 90, 30)];
searchBar.placeholder = #"输入昵称/拜托号";
searchBar.delegate = self;
[searchBar setKeyboardType:UIKeyboardTypeDefault];
[searchBar setReturnKeyType:UIReturnKeySearch];
[searchBar setPlaceholderColor:kcallColor(#"a4a4a4")];
[searchBar setPlaceholderFont:kFont(14)];
[searchBar addTarget:self action:#selector(SearchTextFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
[navgationView addSubview:searchBar];
}
#end
//BKSearchBar The key code
#implementation BKSearchBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// 设置背景
self.backgroundColor = kcallColor(#"7d1d57");
self.returnKeyType = UIReturnKeySearch;
// 设置内容 -- 垂直居中
self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self UI];
}
return self;
}
- (void)UI{
// 设置左边显示一个放大镜
UIImageView *leftView = [[UIImageView alloc] init];
omit...
//右边的view
UIImageView *rightView = [[UIImageView alloc] init];
omit...
}
- (CGRect)placeholderRectForBounds:(CGRect)bounds{
CGRect rect = CGRectMake(self.leftView.right, (self.height - 24) / 2, bounds.size.width, 14);
return rect;
}
- (void)clearText{
self.text = nil;
}
- (void)setPlaceholderColor:(UIColor *)color{
[self setValue:color forKeyPath:#"_placeholderLabel.textColor"];
}
- (void)setPlaceholderFont:(UIFont *)font{
[self setValue:font forKeyPath:#"_placeholderLabel.font"];
}
Thank all!The problem is resolved!because of the runtime!
+ (void)swizzleInstanceMethod:(Class)class originSelector:(SEL)originSelector otherSelector:(SEL)otherSelector
{
Method otherMehtod = class_getInstanceMethod(class, otherSelector);
Method originMehtod = class_getInstanceMethod(class, originSelector);
// 交换2个方法的实现
method_exchangeImplementations(otherMehtod, originMehtod);
}

UIBarButtonItem doesn't appear

I have an issue, when the view is loaded, it will load the UIBarButtonItem, but then i have to set it to nil in "mostra_filtro_btn", but then again in "load_map" i have to set it, but it doesn't show up.
Here is my code:
//
// FirstViewController.m
// House Finder
//
// Created by Giovanni Poli on 12/05/15.
// Copyright (c) 2015 Giovanni Poli. All rights reserved.
//
#import "MapViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Reachability.h"
#import "UIKit/UIKit.h"
#import <Foundation/Foundation.h>
#import "FiltroViewController.h"
#interface MapViewController ()
#end
#implementation MapViewController
#synthesize filtro_controller,overlay_filtro_counter,mappa_controller;
-(void)load_map{
NSLog(#"load_map");
[mapView removeFromSuperview];
[mappa_controller.view removeFromSuperview];
[filtro_controller.view removeFromSuperview];
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
}
- (id) init{
filtro_controller = [[FiltroViewController alloc]init];
[self.view addSubview:filtro_controller.view];
[self addChildViewController:filtro_controller];
return self;
}
- (void)viewDidLoad {
self.title = #"Mappa";
self.navigationItem.title = #"House Finder";
self.navigationController.navigationBar.translucent = FALSE;
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"json"];
NSData *content = [[NSData alloc] initWithContentsOfFile:filePath];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:content options:kNilOptions error:nil];
NSArray * json_all = [json objectForKey:#"results"];
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-40)];
mapView.delegate = self;
mapView.showsUserLocation = NO;
mapView.userInteractionEnabled = YES;
CLLocationCoordinate2D annotationCoord;
self.view.userInteractionEnabled = YES;
NSDictionary * temp;
for (id object in json_all) {
temp = object[#"titolo"];
annotationCoord.latitude = [object[#"lat"] floatValue];
annotationCoord.longitude = [object[#"lon"] floatValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = object[#"titolo"];
annotationPoint.subtitle = object[#"agenzia"];
[mapView addAnnotation:annotationPoint];
}
[mapView showAnnotations:[mapView annotations] animated:YES];
[self.view addSubview:mapView];
[self.view setNeedsDisplay];
}
- (IBAction) mostra_filtro_btn: (id)sender{
NSLog(#"mostra_filtro_btn");
self.navigationItem.rightBarButtonItem = nil;
filtro_controller = [[FiltroViewController alloc]init];
[self.view addSubview:filtro_controller.view];
[self addChildViewController:filtro_controller];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:annotation{
if (annotation == mapViews.userLocation) return nil;
MKPointAnnotation * temp = annotation;
MKAnnotationView * m = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"casa"];
m.canShowCallout = YES;
m.enabled = YES;
m.userInteractionEnabled = YES;
NSString * icon_file = [NSString stringWithFormat:#"%#.png",temp.subtitle];
m.image = [UIImage imageNamed:icon_file];
return m;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(#"overlay prezzo");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
Use the following code to nil the navigation item so it will hide where ever you want
[self.navItem setRightBarButtonItem:nil];
[self.navItem setLeftBarButtonItem:nil];
Try first create the UIButton then put it into the navigation button as follow
UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 44.0f, 30.0f)];
[backButton setImage:[UIImage imageNamed:#"back.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(popVC) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
Since I can't post this as a comment here is what I think is missing inside load_map:
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"load_map");
[mapView removeFromSuperview];
[mappa_controller.view removeFromSuperview];
[filtro_controller.view removeFromSuperview];
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
})
This is a possible solution till you try it. If you share the code from where you call load_map it would be great!
Cheers!
Your code works perfect, as you said you are adding button with method mostra_filtro_btn : in viewDidLoad method, and on click of button, button from navigation bar set to nil.
But the problem is that, from nowhere you calls load_map method. You need to call this method once the button gets nil, to get it back with load_map method.
May you get it.
Enjoy Coding!!

push to vc from UIView class under a view controller

created a class,
GSSFeatureScreenLocationTabView : UIView,
to add multiple view into a scroll view,
the view comes up with buttons which are linked to a selector that is supposed to push to another view controller, It sends the placeID back up but from some reason doesn't push to the next view controller
GSSFeatureScreenLocationTabView.h
#import "featureScreenViewController.h"
#interface GSSFeatureScreenLocationTabView : UIView
{
UIImageView* imageView;
UILabel* titleLabel;
UILabel* distanceLabel;
UILabel* descriptionLabel;
UIButton* pushButton;
}
#property (nonatomic) NSString* placeID;
-(void)setLocationInfo:(NSString*)ID title:(NSString*)title distance:(double)distance description:(NSString*)description imageURL:(NSString*)imageURL;
#end
GSSFeatureScreenLocationTabView.m
#import "GSSFeatureScreenLocationTabView.h"
#import "GSSLocationDetailViewController.h"
#implementation GSSFeatureScreenLocationTabView
#synthesize placeID = _placeID;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 144, 140)];
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 148, 107, 21)];
distanceLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 177, 107, 21)];
descriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 206, 107, 91)];
pushButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 144, 317)];
[titleLabel setText:#""];
[distanceLabel setText:#""];
[descriptionLabel setText:#""];
[descriptionLabel setLineBreakMode:NSLineBreakByWordWrapping];
[pushButton setTitle:#"" forState:UIControlStateNormal];
[pushButton addTarget:self action:#selector(pushToLocation) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:imageView];
[self addSubview:titleLabel];
[self addSubview:distanceLabel];
[self addSubview:descriptionLabel];
[self addSubview:pushButton];
}
return self;
}
-(void)setLocationInfo:(NSString *)ID title:(NSString *)title distance:(double)distance description:(NSString *)description imageURL:(NSString *)imageURL
{
_placeID = ID;
[titleLabel setText:title];
[distanceLabel setText:[NSString stringWithFormat:#"%f", distance]];
[descriptionLabel setText:description];
UIImage* image = [UIImage imageNamed:imageURL];
[imageView setImage:image];
}
-(void) pushToLocation
{
NSLog(#"%s", __FUNCTION__);
featureScreenViewController* fsvc = [[featureScreenViewController alloc]init];
[fsvc pushToLocationWithID:_placeID];
}
#end
in featureScreenViewController.m
- (void)viewDidLoad
{
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE
if (isiPhone5)
{
// this is iphone 4 inch
[scroller setFrame:CGRectMake(0, 251, 320, 317)];
}
else
{
[scroller setFrame:CGRectMake(0, 251, 320, 229)];
}
[self addLocationViews];
}
-(void)addLocationViews
{
int count = (int)[_placeArray count];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(152*count, 317)];
for (int i = 0; i<count; i++) {
_placeObject = [_placeArray objectAtIndex:i];
GSSFeatureScreenLocationTabView * view = [[GSSFeatureScreenLocationTabView alloc]initWithFrame:CGRectMake((152*i), 0, 144, 317)];
[view setLocationInfo:[_placeObject placeID] title:[_placeObject placeName] distance:[_placeObject distacne] description:#"description" imageURL:#"noImage.png"];
[scroller addSubview:view];
}
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
}
-(void) pushToLocationWithID:(NSString*)placeID
{
NSLog(#"\n%s \nplaceID:%#\n\n", __FUNCTION__, placeID);
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
GSSLocationDetailViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"GSSLocationDetailViewController"];
[self presentViewController:vc animated:YES completion:nil];
}
the function -(void) pushToLocationWithID:(NSString*)placeID is called and the log shows the function and placeID, However it doesn't push to the location view controller.
tried creating a button just to link a segue to it and called the performSegue with identifier, doesn't reach prepare for segue and still doesn't push.
However using the same code from another page in an IBAction and it works. Is there someway to call super or something so it goes into the navController and pushes it ?
If i do presentViewController just to test modal like shown above it shows
Warning: Attempt to present <GSSLocationDetailViewController: 0xab85110> on <featureScreenViewController: 0xab9c230> whose view is not in the window hierarchy!
but if i do
[self.navigationController pushViewController:vc animated:YES];
it doesn't show anything in the log and doesn't push.
made a new project with same concept at http://www.narula-tech.com/testScrollPush.zip
You are in a UIView (GSSFeatureScreenLocationTabView) and you are allocating a new viewController (VC2: featureScreenViewController) from there and you are pushing another viewController (VC3: GSSLocationDetailViewController) from there.
But actually your view is in another viewController VC1 and you need to push VC3 from there and not from VC2 which you are allocating but is not "in the scene" or better, in the window hierarchy.
So you should control touches from the viewController and not from the UIView..for this reason the name: view**CONTROLLER**.
Another thing but not related:
name of class should began with the first letter capitol:
So not:
featureScreenViewController* fsvc;
but:
FeatureScreenViewController* fsvc;

how to move to the new view fast in ipad application

I have many view controller when i click on tableView cell it move to new view controller problem is that it takes alot of time to move to the next view may be due to view which is to load fetches data from server here is my code for the view which loads
- (void)viewDidLoad {
appDelegate = (MultipleDetailViewsWithNavigatorAppDelegate *)[[UIApplication sharedApplication] delegate];
UIImageView *bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"Nav.png"]];
[bottomImageView setFrame:CGRectMake(0,690,1024,34)];
[self.view addSubview:bottomImageView];
UIButton *button1=[UIButton buttonWithType:UIButtonTypeCustom];
[button1 setFrame:CGRectMake(10.0, 2.0, 88, 40.0)];
[button1 addTarget:self action:#selector(loginPressed) forControlEvents:UIControlEventTouchUpInside];
[button1 setImage:[UIImage imageNamed:#"logoutN.png"] forState:UIControlStateNormal];
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithCustomView:button1];
self.navigationItem.rightBarButtonItem = button;
self.title=#"Catalog";
popImageView.hidden=YES;
passwordLabel.hidden=YES;
userLabel.hidden=YES;
userNameTextField.hidden=YES;
userPasswordTextField.hidden=YES;
signInButton.hidden=YES;
tableView.hidden=NO;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
searching = NO;
letUserSelectRow = YES;
if(!categoryArray){
categoryArray =[[NSMutableArray alloc] init];
}
if(!userArray){
userArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArray){
subCategoryArray =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayOne){
subCategoryArrayOne =[[NSMutableArray alloc] init];
}
if(!subCategoryArrayTwo){
subCategoryArrayTwo =[[NSMutableArray alloc] init];
}
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
int count=[appDelegate.coffeeArray count];
NSLog(#"Arrays Content Are %d",count);
tableView.backgroundView = nil;
[super viewDidLoad];
}
is there any way so that view loads fast
Your view is not loading fast because of I guess those data set operation in viewDidLoad method . I think those are :
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
The one thing you could do is to move this operations to perform on the background thread . For that move this operations to the separate function and call that to perform on background from the view did load method :
-(void)dataOperations
{
[self setUpData];
[self setUpDataSub];
[self setUpDataSubOne];
[self setUpDataSubTwo];
}
and in viewDidLoad call this function in background:
[self performSelectorInBackground:#selector(dataOperations) withObject:nil];
Or you can directly call those method from viewDidLoad like :
[self performSelectorInBackground:#selector(setUpData) withObject:nil];

Resources