TabBar Segue when selecting row in table view controller - core-data

I already have a segue set in place in my table view controller for an add button press. Now I want to have another segue for when the user selects on the newly added object. My code looks like this so far:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Add Vehicle Segue"])
{
NSLog(#"Setting RootViewController as a delegate of AddViewController");
AddViewController *addViewController = segue.destinationViewController;
addViewController.delegate = self;
addViewController.managedObjectContext = self.managedObjectContext;
}
I think I will need to add an else if next to take care of the tab bar segue but don't know how to do that.
Also the tab bar view is just there to show the two tabs so I don't believe I will preform the segue with the reference to core data.
Thanks in advance.!
My storyboard flow

If you do not want to pass value to the next view controller or do any actions that need to done before performing the segue, but just display the tab bar then you don't need to add anything in the prepareForSegue:sender: method. If you do have to do something when performing the segue add and else condition as there is only two segues and write your code inside the else block.

Related

How to guarantee that I get the `HTREEITEM` for the item that the user right-clicked on in a CTreeControl

I have a window which has a CTreeCtrl. A user can right-click any element and display a context menu. From there they can choose to delete the entry. Something like this:
Here is a snippet of the context menu item handler:
void CAssignHistoryDlg::OnDeleteFromAssignmentHistory()
{
CString strINI = theApp.GetAssignHistoryPath();
HTREEITEM hItem = m_treeHistory.GetSelectedItem();
CString strName, strDeletedName, strEntry;
if (m_treeHistory.GetParentItem(hItem) != nullptr)
{
// The user has picked one of the history dates.
// So the parent should be the actual name.
hItem = m_treeHistory.GetParentItem(hItem);
// Now OK to proceed
}
strName = ExtractName(hItem);
GetParent()->EnableWindow(FALSE);
strEntry.Format(IDS_TPL_SURE_DELETE_FROM_ASSIGN_HIST, strName);
if (AfxMessageBox(strEntry, MB_YESNO | MB_ICONQUESTION) == IDNO)
{
The image shows my problem. If I first click on Test, so that it is selected and bright blue and then right-click, it shows Test in the popup message. This is fine. But ...
If the first name is initially selected, and I go ahead and directly right-click Test, even though it seems to go blue (as if selected), m_treeHistory.GetSelectedItem() is returning the original, first name. I think I am describing it not very well.
In short, I want to guarantee that I get the HTREEITEM for the item that the user right-clicked on. What I have is not 100% fool-proof.
If it helps, this is how I display the context menu:
void CAssignHistoryDlg::OnNMRclickTreeHistory(NMHDR *pNMHDR, LRESULT *pResult)
{
CMenu mnuContext, *pMnuEdit = nullptr;
CPoint ptLocal;
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
GetCursorPos(&ptLocal);
mnuContext.LoadMenu( IDR_MENU_SM_ASSIGN_HIST_POPUP );
pMnuEdit = mnuContext.GetSubMenu( 0 );
if (pMnuEdit != nullptr)
{
pMnuEdit->TrackPopupMenu( TPM_LEFTALIGN|TPM_LEFTBUTTON,
ptLocal.x, ptLocal.y, this, nullptr );
}
*pResult = 0;
}
So to recap, at the moment the user must physically left click on a item in the tree to select it. Then they can right-click and it will offer to delete this person. But if they go ahead and just right-click on anyone, it will not offer to delete THAT person.
You can get the actual tree item at any given point using the HitTest() member of the CTreeCtrl class. Exactly how and where you do this will depend on your code design but, if you have a pointer to your CTreeCtrl (pwTree in the code below), then you can do something like this:
CPoint ptLocal;
GetCursorPos(&ptLocal);
pWTree->ScreenToClient(&ptLocal); // May not be required in certain handlers?
HTREEITEM hItem = pWTree->HitTest(ptLocal); // Remember to check for NULL return!
You can then either use the returned hItem directly, or use it to explicitly set the tree's selection (to that item), before doing any further processing.
The MS doc: https://learn.microsoft.com/en-us/cpp/mfc/reference/cwnd-class?view=vs-2019 doesn't have a "click" handler, it has CWnd::OnRButtonDblClk, CWnd::OnRButtonDown and CWnd::OnRButtonUp. Which one are you handling?
The reason for your defect might be that you don't let the tree control handle that right button event (to select that new item).
I would suggest to use CWnd::OnContextMenu instead.

Prevent row click event in YUI Datatable

I have a YUI data table. When we click on any row of this data table, there is an alert box.
vtgtTbl.on('rowClickEvent',function(oArgs){
alert("a");
}
I have a checkbox. what i want is that when that checkbox is true then row click will work, and not when it is false. so is there is any method in YUI to attach and detach these events
Within the rowClick event handler callback you can add a check for the checkbox in the following way
vtgtTbl.on('rowClickEvent',function(oArgs){
var checkBoxNode = Y.one('#checkboxId');
if (checkBoxNode.checked) {
alert("a");
}
}
Hope it solves the problem.

How to pass NSMutable arrays to table view?

I am having three buttons in a view. and three actions for three buttons. In the first view i have declared three buttons and three actions for that three buttons.
In the next view i have taken table view. And I have taken three mutable arrays.
If the first button is pressed the first mutable array items is to be passed into tableview.
If the second button is pressed the second mutable array items is to be passed into tableview.
If the third button is pressed the third mutable array items is to be passed into tableview.
Can anybody give me the code.
Its simple..you just need to change the datasource of the tableView.... in cellForRowAtindexPath method whatever array you are passing just change that on buttonClick event and reload the tableView
Hope this will help you.
Edit Added : for NSNotification
FirstView.m
-(void)buttonAction{
[[NSNotificationCenter defaultCenter] postNotificationName: #"changeArray" object:yourArray userInfo:nil];
}
SecondView.m
-(void)ViewDidLoad{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receiveTestNotification:) name:#"changeArray" object:nil];
}
-(void)receiveTestNotification:(NSNotification)iNotification{
NSMutableArray *myArray = [iNotification object];
//do your changes.
}

MKMap annotation selection

I want to check when he user presses the annotation (the bubble on top of the pin). I tried the following :
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{}
but it fires up when i press the pin. How can i check when the user actually presses on the annotation bubble?
You can first put a right accessory button and set an separate action for it as such:
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
customPinView.rightCalloutAccessoryView = rightButton;
you can implement the showDetails method with the function that you like

C# TableLayoutPanel replace control?

I was wondering if it was possible to replace one control in a TableLayoutPanel with another at runtime. I have a combo box and a button which are dynamically added to the TableLayoutPanel at runtime, and when the user selects an item in the combo box and hits the button, I'd like to replace the combobox with a label containing the text of the selected combo box item.
Basically, if I could simply remove the control and insert another at it's index, that would work for me. However I don't see an option like "splice" or "insert" on the Controls collection of the TableLayoutPanel, and I was wondering if there was a simple way to insert a control at a specific index. Thanks in advance.
Fixed this by populating a panel with the two controls I wanted to swap and putting that into the TableLayoutPanel. Then I set their visibility according to which I wanted to see at what time.
This is what I've been able to come up with for what I needed. It gets the position of the ComboBox and makes a new label using the selected value.
// Replaces a drop down menu with a label of the same value
private void lockDropMenu(ComboBox dropControl)
{
TableLayoutPanelCellPosition pos = myTable.GetCellPosition(dropControl);
Label lblValue = new Label();
myTable.Controls.Remove(dropControl);
if (dropControl.SelectedItem != null)
{
lblValue.Text = dropControl.SelectedItem.ToString();
lblValue.Font = lblValue.Font = dropControl.Font;
// Just my preferred formatting
lblValue.AutoSize = true;
lblValue.Dock = System.Windows.Forms.DockStyle.Fill;
lblValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
myTable.Controls.Add(lblValue, pos.Column, pos.Row);
}
}

Resources