replacement for tabbar selected index - objective-c

I have an old app where I have 5 tabs. Each tab have list of ads & there is details. Also each tab have respective add ad. Design for all 5 tabs is same except some changes, so I decided to use 1 screen only for all 5 tabs.
Now what I am doing is while add ad, I am checking which tab I am and based on tab bar index, I am showing hiding fields. Same is applicable for details screen also. Sample code is as shown below.
if (self.tabBarController.selectedIndex==0) {
field1.hidden = NO;
} else if (self.tabBarController.selectedIndex==1) {
field1.hidden = NO;
} else if (self.tabBarController.selectedIndex==2) {
field1.hidden = NO;
} else if (self.tabBarController.selectedIndex==3) {
field1.hidden = NO;
} else if (self.tabBarController.selectedIndex==4) {
field1.hidden = YES;
}
Now I have around 15 fields for each form so I write this code for all fields.
What I noticed that client change the tab bar position continuously so I was looking for efficient way of doing it.
Right now what I do is at all places manually change index positions by doing Search-Replace, however I dont like this.
I was looking for a way where instead of selectedIndex, I was looking for someconstant value that I will assign to tab item of tab bar, so my code will change as below
if (self.tabBarController.selectedIndex==adType_News) {
field1.hidden = NO;
} else if (self.tabBarController.selectedIndex==adType_Occasions) {
.
.
And so on...
This way, I only need to change in the storyboard and code level will not have any changes.
Is there way where I can achieve this?
Main Issue
As client ask to change tab bar completely, I need to make changes of selectedIndex changes at all places which I don't like and feel more in-efficient way. So I was looking for a way where I will make change in storyboard only and coding level there won't be any change.
The main issue for me is changing selectedIndex in all files which make more error.

I think I understand the question to mean that the code is full of number literals, referring to the selected index of the tabbar, and the business requirements about the ordering of items are shifting. Fix by changing the literals to something symbolic that can be controlled centrally:
// in a new file, indexes.h
#define INDEXA (0)
#define INDEXB (1)
#define INDEXC (2)
// wherever existing code refers to the tab selection
#import "indexes.h"
// in the code, for example if selectedIndex == 2, change to
if (self.tabBarController.selectedIndex==INDEXC) {
// ...

Related

Hide a view in Titanium so that it does not take physical space

In titanium it is possible to hide a view like so:
$.foo.hide()
or
$.foo.visible = false
However, in both cases the object still seems to take physical space. It is just invisible. In other words it is similar to the CSS property visibility: hidden.
I want it so that it disappears and take no physical space in terms of width or height, so it's similar to the CSS property display: none
How can I do this?
The best hacky solution I have is the following:
$.foo.width = 0;
$.foo.height = 0;
$.foo.left = 0;
$.foo.right = 0;
But that means when I want to make it visible again, I have to set all those properties back to their original values which is a pain and hard to maintain.
First of all, don't afraid of doing some hard coding ;)
Coming to your query, yes, this is true that hiding a view just hide it from UI, but physical-space is still there.
To do what you want, you will need to either remove view on hide & create it on show, or you can use absolute layout in some tricky way.
Other way could be to animate this view using transform property like this:
// on hide
$.foo.animate({
duration : 100,
transform : Ti.UI.create2DMatrix({scale:0})
}, function () {
$.foo.visible = false;
});
// on show
$.foo.visible = true; // we need to make it visible again before resetting its UI state since we hid it after completion of animation in above code
$.foo.animate({
duration : 100,
transform : Ti.UI.create2DMatrix() // passing empty matrix will reset the initial state of this view
});
OR
this could also work but never tried this:
// on hide
$.foo.transform = Ti.UI.create2DMatrix({scale:0});
$.foo.visible = false;
// on show
$.foo.visible = true;
$.foo.transform = Ti.UI.create2DMatrix();

Tabbing Through Lightswitch VS2013 HTML Table

I have a simple VS2013 Lightswitch application that I need some help on.
There are two tables:
Materials
ID int
Product String
Containers
ID int
Name String
Inventory Double
Comments String
The relationship between Containers and Materials is a one(Materials)-to-infinite(Containers).
I created a custom Browse screen for Containers with a single Table element and some custom scripting for adding and saving the new containers, all of which is working fine.
My problem is that when a user clicks on the html table and starts to edit the items within, the tab key on the keyboard does not work as expected. Every time the keyboard tab is pressed, the first header cell of the HTML table is highlighted. Progress through the rest of the columns within the table does not happen. I did Google this and found this blog but it did not seem to effect anything.
Oddly enough, when I resize my IE screen to force the RWD, the tabbing works as expected.
Any thoughts on a remedy?
refer to this thread I asked myself on the MSDN Forums which solved this problem:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/8c0055c8-367b-407d-a0f4-a33ae81dcc0e/html-client-edit-multiple-lines-of-data-in-a-table?forum=lightswitch
and incase the URL breaks:
if you go to the msls-2.5.1.js file, and go to line 28565, change the code here which shoul start with:
switch (e.keyCode) {
and end with
break;
}
});
and change it to:
switch (e.keyCode) {
case $.mobile.keyCode.ENTER:
//if (header) {
// sortTableByColumn(table, header.cellIndex);
//} else {
// msls_ui_CollectionControl.selectFocusedItem(table);
//}
break;
//case $.mobile.keyCode.SPACE:
// if (header) {
// sortTableByColumn(table, header.cellIndex);
// } else {
// msls_ui_CollectionControl.toggleFocusedItem(table);
// }
// break;
case $.mobile.keyCode.TAB:
//Xpert360: tab in grid
//if (target.tagName.toLowerCase() != "input")
// updateSelectedHeader(table, table._headerRowElement[0]);
break;
}
});
this enables be to tab through a table view in Lightswitch HTML

how can i give multiple actions to button on iPhone

I have two buttons,if the first button is clicked two textfields will come and the second button dimension will change to next to the textfields.Now if i click the second button one textfield will appear.I did all those things.Now my question is if we click the second button,textfield will appear with what ever the dimensions we have given,but if we click the second button after clicking the first button also dimensions should change.Can any one help to do this.
Thank You
you can add multiple selectors on a single button for different control states
Your question is vaguely phrased. If I understood correctly, when the second button is pressed, you want two different actions done depending on whether the first button has previously been pressed or not. If that's the case, the solution is to define a boolean flag, which will be set to YES when the first button is pressed, and will be set to NO (if needed) after the second button's action is completed.
In your header file:
#interface yourViewController: UIViewController {
BOOL firstButtonFlag;
}
And in yourViewController.m file:
-(void)viewDidLoad {
firstButtonFlag = NO; // technically redundant line, just to show the concept
}
-(IBAction)firstButtonPressed {
firstButtonFlag = YES;
// whatever action you want done
}
-(IBAction)secondButtonPressed {
if (firstButtonFlag) {
// whatever action if first button had been pressed before
firstButtonFlag = NO; // resetting the flag for next round
}
else {
// whatever action if first button had NOT been pressed before
}
}

How to remove frame attachment

if (isGameOne == TRUE and isGameTwo == FALSE){
x.view.frame = xGraph->theGraph.frame;
y.view.frame = yGraph->theGraph.frame;
} else {
/*remove above frame here*/
}
Above is my script i am working with. When isGameOne is true, i want it to attach x.view.frame to xGraph->theGraph.frame; And same for 'y', but this works fine.
What i am having an issue with is understanding how i would remove x.view.frame the frame if isGameOne is not true (false).
I am sure its probably something really easy to do, but i am still getting my hand dirty with objective-c. Sorry for my ignorance
Cheers
=========[ How to do this ]========
I actually have a button that quits game one, so inside the gameOne method i have
if (isGameOne == TRUE and isGameTwo == FALSE){
x.view.frame = xGraph->theGraph.frame;
y.view.frame = yGraph->theGraph.frame;
}
inside my quit button method i added:
isGameTwo = TRUE;
isGameOne = FALSE;
if (isGameOne == FALSE and isGameTwo == TRUE) {
/* code to remove *DoodlePad from *Grap */
[xDoodlePad.view setHidden:YES];
[yDoodlePad.view setHidden:YES];
}
It depends on what you are doing with those frames. If you want them to be moved to another location on the screen, you could predefine that frame elsewhere and assign it, or you could use CGRectMake to create a specific frame right there.
If you are wanting to hide/show the views based on this condition, you should already have the appropriate frames set before the conditional and just call setHidden on the views with the appropriate argument.
Note that CGRects are structs, so there is assignment of the value itself taking place. You are not maintaining a reference to the other frame.

How can I set the default state of a UISegmentedControl?

Is there a way to set the starting selected segment in a UISegmentedControl in Interface Builder, or do I have to do it in the code? If it's in the code, is viewDidLoad the best place to set it?
From code, you can do:
self.segmentedControl.selectedSegmentIndex = someDefaultIndex
Whether you should set it in viewDidLoad: or not depends entirely on the structure of your application. For example, if your app is starting up and loading the view for the first time and needs to set the control to whatever value it had during the previous run of the app, then it definitely makes sense to do it there.
In Interface Builder when you select UISegmentedControl object on your UI, then in attributes pane, in segment control there's segment drop down menu, select segment that you want selected (0,1 and so on) and tick the 'selected' option below it.
Select default value for your UISegmentedControl via storyBoard
Open ur storyboard and select the UISegmentedControl
Select atributes inspector of your UISegmentedControl (in the right corner)
Search the 'segment' atribute and open de dropdown.
Select the item you want to be selected by default.
Mark the selected checkbox to set selected by default.
If you don't use storyboards and want to set a default index after some setup/networking like me, this little snippet will select something if the user hasn't. I placed this in my subclass of UISegmentedControl, but you could place this anywhere. (Swift 3)
Decl: var UISegmentedControlNoSegment: Int { get }
Desc: A segment index value indicating that there is no selected segment. See selectedSegmentIndex for further information.
Short version:
if selectedSegmentIndex == UISegmentedControlNoSegment {
selectedSegmentIndex = initialIndex
}
Longer version
func reloadData() {
guard let numberOfItems = dataSource?.numberOfItems() else {
return
}
removeAllSegments()
for index in 0...numberOfItems {
insertSegment(with: $image, at: index, animated: false)
}
if selectedSegmentIndex == UISegmentedControlNoSegment {
selectedSegmentIndex = initialIndex
}
}
After clicking the Segmented Control go to where you created the segments and choose the one you want be default. Then below that there will be a Box with "Selected" by it. Select that and it will be default.