I have UISplitView with many detailViewControllers it works fine but problem is that when i from any of the detailViewController move to LoginViewController and then back then i want that UIsplitViewController should have detailView controller which is firstViewController
here is the tableView did select method for RootViewController
[self.appDelegate.splitViewController viewWillDisappear:YES];
NSMutableArray *viewControllerArray=[[NSMutableArray alloc] initWithArray:[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] viewControllers]];
[viewControllerArray removeLastObject];
if (row == 0) {
self.firstDetailViewController=[[[FirstDetailViewController alloc] init]autorelease];
[viewControllerArray addObject:self.firstDetailViewController];
self.appDelegate.splitViewController.delegate = self.firstDetailViewController;
}
if (row == 1) {
self.secondDetailViewController=[[[SecondDetailViewController alloc]init]autorelease];
[viewControllerArray addObject:self.secondDetailViewController];
self.appDelegate.splitViewController.delegate = self.secondDetailViewController;
}
if (row == 2) {
self.myLearningViewController=[[[MyLearningViewController alloc]init]autorelease];
[viewControllerArray addObject:self.myLearningViewController];
self.appDelegate.splitViewController.delegate = self.myLearningViewController;
}
if (row == 3) {
self.communityViewController=[[[CommunityViewController alloc]init]autorelease];
[viewControllerArray addObject:self.communityViewController];
self.appDelegate.splitViewController.delegate = self.communityViewController;
}
if (row == 4) {
self.reportsViewController=[[[ReportsViewController alloc]init]autorelease];
[viewControllerArray addObject:self.reportsViewController];
self.appDelegate.splitViewController.delegate = self.reportsViewController;
}
if (row == 5) {
self.walkInViewController=[[[WalkInViewController alloc]init]autorelease];
[viewControllerArray addObject:self.walkInViewController];
//self.appDelegate.splitViewController.delegate = self.secondDetailViewController;
self.appDelegate.splitViewController.delegate = self.walkInViewController;
}
if (row == 6) {
self.postDataViewController=[[[PostDataViewController alloc]init]autorelease];
[viewControllerArray addObject:self.postDataViewController];
self.appDelegate.splitViewController.delegate = self.postDataViewController;
}
[[self.appDelegate.splitViewController.viewControllers objectAtIndex:1] setViewControllers:viewControllerArray animated:NO];
[self.appDelegate.splitViewController viewWillAppear:YES];
[viewControllerArray release];
I want when login button is clicked then it should set the detailViewController of rootViewCOntroller to firstDetailViewController
-(IBAction)loginButton{
}
back to login
appDelegate.window.rootViewController=appDelegate.self.loginviewcontroller;
[appDelegate.window makeKeyAndVisible];
login to detailviewcontroller is alreading working you
Related
Say, In my self.navigationController.viewControllers I have n number of viewControllers. Within them, I only want to remain 2 viewControllers in my self.navigationController.viewControllers. One is at 0 index & another one is at 1 index. Here is my code.
NSMutableArray *VCs = [NSMutableArray arrayWithArray: self.navigationController.viewControllers];
NSMutableArray *savedVCsArray = [[NSMutableArray alloc] init];
for (int i = 0; i < [VCs count]; i++) {
UIViewController *vc = VCs[i];
if ([vc isKindOfClass:[LanguageSettingsViewController class]]) {
[savedVCsArray insertObject:vc atIndex:0];
} else if ([vc isKindOfClass:[SignInViewController class]]) {
[savedVCsArray insertObject:vc atIndex:1];
}
}
[self.navigationController setViewControllers:savedVCsArray];
NSLog(#"counts %i", [self.navigationController.viewControllers count]);
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
But, here I always get NSLog(#"counts %i", [self.navigationController.viewControllers count]); 0. Is there I am missing something? Thanks in advance. Glad if you reply.
xcode Version 8.3.2 (8E2002)
iOS 10.3
Make sure you confirm that you actually have the VCs you want:
UIViewController *langVC = nil;
UIViewController *signVC = nil;
for (UIViewController *vc in self.navigationController.viewControllers) {
if ([vc isKindOfClass:[LanguageSettingsViewController class]]) {
// [savedVCsArray insertObject:vc atIndex:0];
langVC = vc;
} else if ([vc isKindOfClass:[SignInViewController class]]) {
// [savedVCsArray insertObject:vc atIndex:1];
signVC = vc;
}
}
if (langVC == nil || signVC == nil) {
NSLog(#"Problem exists because langVC is %# / signVC is %#", langVC, signVC);
} else {
[self.navigationController setViewControllers:#[langVC, signVC] animated:YES];
}
I have a textfield in my app in which a user can choose a Group they belong to, along with several other fields. When they get to the Group TextField, it pops up a UIPickerView that has several choices that have already been created, along with an option to "Create New Group". When that option is chosen, I want the UIPickerView to go away, and have the keyboard pop back up so they can type again. I can get the picker view to appear and to go away, but can't get the keyboard back. Here is code so far.
-(void)addPickerView{
__block NSMutableArray *arr = [[NSMutableArray alloc] init];
PFQuery *rejectedNumber = [PFQuery queryWithClassName:#"Group"];
[rejectedNumber orderByAscending:#"GroupName"];
[rejectedNumber findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!objects) {
// Did not find any UserStats for the current user
NSLog(#"NotFound");
} else {
pickerArray = objects;
[myPickerView reloadAllComponents];
}
}];
//pickerArray = GoGo;
self.theView.signUpView.additionalField.delegate = self;
[self.theView.signUpView.additionalField setPlaceholder:#"Choose Group"];
myPickerView = [[UIPickerView alloc]init];
myPickerView.dataSource = self;
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
initWithTitle:#"Done" style:UIBarButtonItemStyleDone
target:self action:#selector(finishIt)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:
CGRectMake(0, self.view.frame.size.height-
self.theView.signUpView.additionalField.frame.size.height-50, 320, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:
doneButton, nil];
[toolBar setItems:toolbarItems];
self.theView.signUpView.additionalField.inputView = myPickerView;
self.theView.signUpView.additionalField.inputAccessoryView = toolBar;
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return [pickerArray count] + 1;
}
#pragma mark- Picker View Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component{
if (row == 0)
[self.theView.signUpView.additionalField.inputView removeFromSuperview];
[self.theView.signUpView.additionalField becomeFirstResponder];
}
else {
[self.theView.signUpView.additionalField setText:self.theGroup];
}
}
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSString *groupName = #"Create New Group";
if (row != 0)
{
PFObject *object = pickerArray[row - 1]; // -1 to handle the array index
self.theGroup = object[#"GroupName"];
groupName = object[#"GroupName"];
}
return groupName;
}
First thing i noticed is, you missed a braces here after if condition:
if (row == 0)
[self.theView.signUpView.additionalField.inputView removeFromSuperview];
[self.theView.signUpView.additionalField becomeFirstResponder];
}
Instead use this:
if (row == 0) {
[self.theView.signUpView.additionalField resignFirstResponder];
self.theView.signUpView.additionalField.inputView = nil;
[self.theView.signUpView.additionalField becomeFirstResponder];
}
I've been brought in on this project where the previous developers made custom table cells and headers by using xib files and then registering the nibs like so:
[self.accountTable registerNib:[UINib nibWithNibName:kNonATITableViewCellLandscapeNib bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kNonATITableViewCellLandscapeIdentifier];
[self.accountTable registerNib:[UINib nibWithNibName:kNonATITableHeaderLandscapeNib bundle:[NSBundle mainBundle]] forCellReuseIdentifier:kNonATITableHeaderLandscapeId];
The header files have buttons in them and uiimageviews. The buttons are for sorting, the uiimageviews for an arrow icon to show you the direction of the sort (asc, desc). All the buttons and imageviews are IBOutlets. All the buttons are linked to an IBAction:
- (IBAction)sortButtonTouched:(id)sender;
The file also has two other properties:
#property (nonatomic, assign) SortType currentSortingOption;
#property (nonatomic, strong) UIButton* btnLastTouched;
Here is sortButtonTouched:
- (IBAction)sortButtonTouched: (UIButton*) buttonTouched {
if (!self.btnLastTouched) {
self.btnLastTouched = buttonTouched;
}
NSString* strFieldToSort;
UIImageView* ivSortImage;
NSArray* arrSortIcons = [[NSArray alloc] initWithObjects:self.ivAccountSort,self.ivNameSort, self.ivAddressSort, self.ivCitySort, self.ivZipSort, self.ivLastCallSort, self.ivMileageSort, nil];
//get the image for the button selected
if (buttonTouched.tag == 0) {
strFieldToSort = #"customerNumber";
ivSortImage = self.ivAccountSort;
} else if (buttonTouched.tag == 1) {
strFieldToSort = #"customerName";
ivSortImage = self.ivNameSort;
} else if (buttonTouched.tag == 2) {
strFieldToSort = #"address";
ivSortImage = self.ivAddressSort;
} else if (buttonTouched.tag == 3) {
strFieldToSort = #"city";
ivSortImage = self.ivCitySort;
} else if (buttonTouched.tag == 4) {
strFieldToSort = #"zip";
ivSortImage = self.ivZipSort;
} else if (buttonTouched.tag == 5) {
strFieldToSort = #"lastCallDate";
ivSortImage = self.ivLastCallSort;
} else if (buttonTouched.tag == 6) {
strFieldToSort = #"mileage";
ivSortImage = self.ivMileageSort;
}
//set the sort option and add icon
if (!self.currentSortingOption) {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
} else {
if (![self.btnLastTouched isEqual:buttonTouched]) {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
} else {
if (self.currentSortingOption == SORT_ASC) {
self.currentSortingOption = SORT_DESC;
[ivSortImage setImage:[UIImage imageNamed:Descending_Icon]];
} else {
self.currentSortingOption = SORT_ASC;
[ivSortImage setImage:[UIImage imageNamed:Ascending_Icon]];
}
}
}
//show and hide
for(int i=0; i<arrSortIcons.count; i++) {
UIImageView* ivThisImage = [arrSortIcons objectAtIndex:i];
if (buttonTouched.tag == i) {
[UIView animateWithDuration:.25 animations:^(void) {
ivThisImage.alpha = 1.0;
}];
} else {
[UIView animateWithDuration:.25 animations:^(void) {
ivThisImage.alpha = 0.0;
}];
}
}
//call back to routing view controller and sort results based on sort order and field selected
NSDictionary* dictUserData = [[NSDictionary alloc] initWithObjectsAndKeys:
#"Sort Non-ATI", #"Action",
strFieldToSort, #"Field To Sort",
[NSNumber numberWithLong:self.currentSortingOption], #"Sortng Option",
nil];
[[NSNotificationCenter defaultCenter] postNotificationName:#"rvc" object:self userInfo:dictUserData];
self.btnLastTouched = buttonTouched;
}
And the notification fires this method:
- (void) sortNonATIResults : (NSDictionary*) dictSortParams {
if (self.arrNonATIResults.count > 0) {
NSString* sortKey = [dictSortParams objectForKey:#"Field To Sort"];
//change the field to sort to match the customerInfo object properties...
NSNumber* numSortType = [dictSortParams objectForKey:#"Sortng Option"];
BOOL isAsc = YES;
if ([numSortType intValue] == 2) {
isAsc = NO;
}
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:isAsc];
NSArray* arrSortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSArray* arrSortedNonATIResults = (NSArray*)[self.arrNonATIResults sortedArrayUsingDescriptors:arrSortDescriptors];
self.arrNonATIResults = [arrSortedNonATIResults mutableCopy];
self.arrDatasource = self.arrNonATIResults;
[self.accountTable reloadData];
}
}
There are two problems right now. The icons are not showing up if the notification is sent. Comment out the notification and they function as expected. The other problem is that the property currentSortingOption doesn't retain it's value. I think both issues are related but I am not 100% sure. When the tableview is reloaded, does the header get instantiated again? This would make sense to me since then the uiimageviews would be reset with no image and the property would lose it's value and reset to 0 (it is the value of a typedef).
So, I am correct, how can I resolve this and if not, what could be causing the problems?
Thanks
OK, sorry for posting and then solving my problem right away, I guess sometimes you just need to write out the problem to find the solution. All I needed to do was not reload the table but just reload the rows. Here's the updated method:
(void) sortNonATIResults : (NSDictionary*) dictSortParams {
if (self.arrNonATIResults.count > 0) {
NSString* sortKey = [dictSortParams objectForKey:#"Field To Sort"];
//change the field to sort to match the customerInfo object properties...
NSNumber* numSortType = [dictSortParams objectForKey:#"Sortng Option"];
BOOL isAsc = YES;
if ([numSortType intValue] == 2) {
isAsc = NO;
}
NSSortDescriptor* sortDescriptor = [[NSSortDescriptor alloc] initWithKey:sortKey ascending:isAsc];
NSArray* arrSortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
NSArray* arrSortedNonATIResults = (NSArray*)[self.arrNonATIResults sortedArrayUsingDescriptors:arrSortDescriptors];
self.arrNonATIResults = [arrSortedNonATIResults mutableCopy];
self.arrDatasource = self.arrNonATIResults;
dispatch_async(dispatch_get_main_queue(), ^{
NSMutableArray *indexPathArray = [[NSMutableArray alloc] init];
for (NSInteger section = 0; section < [self.accountTable numberOfSections]; ++section)
{
for (NSInteger row = 0; row < [self.accountTable numberOfRowsInSection:section]; ++row)
{
[indexPathArray addObject:[NSIndexPath indexPathForRow:row inSection:section]];
}
}
[self.accountTable reloadRowsAtIndexPaths:indexPathArray withRowAnimation:UITableViewRowAnimationNone];
[self.accountTable scrollsToTop];
});
}
}
I'm working on a baseball game app that contains multiple Modal View Controllers. However, when I make the modal transition from "BasicGameSetupViewController" to "BasicViewController", the transition happens (because I have NSLog statements within my ViewDidLoad method in the BasicViewController), but the actual view does not update. Here is the method where I transition to the BasicViewController (this code is in BasicGameSetupViewController):
- (IBAction)pressedBeginPlay:(id)sender {
numOfInnings = [selectInnings selectedSegmentIndex];
numOfInnings = numOfInnings + 1;
row = [teamSelector selectedRowInComponent:0];
visitor = [teams objectAtIndex:row];
row = [teamSelector selectedRowInComponent:1];
home = [teams objectAtIndex:row];
NSLog(#"%#", visitor);
NSLog(#"%#", home);
if([awaySelect selectedSegmentIndex] == 0)
{
awayPlayer = #"Human";
}
else
{
awayPlayer = #"CPU";
}
if([homeSelect selectedSegmentIndex] == 0)
{
homePlayer = #"Human";
}
else
{
homePlayer = #"CPU";
}
[self performSegueWithIdentifier:#"startBeginnerToBasic" sender:self];
}
(This block also has a "prepareForSegue" method)
And here is the viewDidLoad method in BasicViewController:
- (void)viewDidLoad{
NSLog(#"Made it to basic View controller");
homeLineup = [[NSMutableArray alloc] initWithCapacity:9];
visitorLineup = [[NSMutableArray alloc] initWithCapacity:9];
batter = [[NSMutableArray alloc] initWithCapacity:22];
homePitcher = [[NSMutableArray alloc] initWithCapacity:22];
awayPitcher = [[NSMutableArray alloc] initWithCapacity:22];
pitcher = [[NSMutableArray alloc] initWithCapacity:22];
homeAlreadyPitched = [[NSMutableArray alloc]initWithCapacity:5];
awayAlreadyPitched = [[NSMutableArray alloc] initWithCapacity:5];
NSLog(#"arrays initialized");
[super viewDidLoad];
[self setUpTeams];
[self checkForComputer];
[self newBatter];
[self atBat];
// Do any additional setup after loading the view.
}
I'm completely stumped as to why my view isn't showing. The NSLog statements that are in the ViewDidLoad code block above show up, but the I can't get the view to show. Does anyone have any ideas?
Thank you in advance for your help!
I got the following problem: The labels always change to the ones definied in tag 9001. Could someone help me spot my error?
ViewController.m:
- (IBAction)switch0:(id)sender
{(button.tag = 9001);
UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
second.buttonTag = buttonPressed.tag;
}
- (IBAction)switch2:(id)sender2
{ (button2.tag = 9002);
UIButton *buttonPressed = (UIButton *)sender2;
SecondViewController *third =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:third animated:YES];
second.buttonTag = buttonPressed.tag;
}
SecondViewcontroller.m
- (void)viewDidLoad
{
[super viewDidLoad];
if (buttonTag == 9001) {
self.label1.text = [[NSString alloc] initWithFormat:#"Radnomtext"];
self.label2.text = [[NSString alloc] initWithFormat:#"Randomtext"];
self.label3.text = [[NSString alloc] initWithFormat:#"Randomtext?"];
}
if (buttonTag == 9002) {
self.label1.text = [[NSString alloc] initWithFormat:#"Radnomtext2"];
self.label2.text = [[NSString alloc] initWithFormat:#"Randomtext2"];
self.label3.text = [[NSString alloc] initWithFormat:#"Randomtext2?"];
Heres an example and your presenting the view twice I took out the modal in this example:
- (IBAction)switch0:(id)sender
{
UIButton *buttonPressed = (UIButton *)sender;
SecondViewController *second =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
NSInteger tagToSet = 9001;
second.buttonTag = tagToSet;;
[self.navigationController pushViewController:second animated:YES];
}
and using the keyword switch is no good. It is a reserved word in Objective C.
Maybe because you forgot to close the ending bracket for first if?
if (buttonTag == 9001) {
self.label1.text = [[NSString alloc] initWithFormat:#"Radnomtext"];
self.label2.text = [[NSString alloc] initWithFormat:#"Randomtext"];
self.label3.text = [[NSString alloc] initWithFormat:#"Randomtext?"];
} // bracket supposed to be here
if (buttonTag == 9002) {
or maybe you set buttonTag to incorrect instance?
- (IBAction)switch2:(id)sender2
{
UIButton *buttonPressed = (UIButton *)sender2;
SecondViewController *third =[[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:third animated:YES];
second.buttonTag = buttonPressed.tag; // supposed to be third?
[self.navigationController pushViewController:third animated:YES];
(button2.tag = 9002);
}
And to be safe, you should set buttonTag before presentModalViewController.