i fetch data from server and populate VableView according to income data array. I want to my app display the details of the string in a new view when the user clicks on the cell. I've populated the TableView and connected a new view and can push new view by clicking the cell, but i have no idea about how to connect all elements of array with the second view.
//the result is JSON data i bring from a url
NSMutableArray *messageContentArray= [[result objectForKey:#"message"] valueForKey:#"message"];
NSUserDefaults *savedContec=[NSUserDefaults standardUserDefaults];
[savedContec setObject:messageContentArray forKey:#"messageArray"];
This is my code of parsing the data and saving it and:
NSArray *someThing=[[NSUserDefaults standardUserDefaults] valueForKey:#"messageArray"];
cell.textLabel.text= [someThing objectAtIndex:indexPath.row];
// NSString *st= [someThing substringToIndex:10];
// i will show first 10 charakters from the message as the cell.textlabe.tex but haven't
// prepared that part.. What i want is, when i click a cell, in the second view display
// all the text for that element of array
this is how i populate the tableview cells. As i explained in the code, when i click a cell, i want to display all the text for that element of array in the second view.
NOTE: I have prapared views and connections
wether u have done any sample app, how to display the data onto views...
check the below sample
http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1
there are 3 parts in this tutorial, go through it, u will come to know how to use it in ur app.
Related
I have a UITableViewController with several cells. Users can enable select feature by tapping on Select button. Once user taps on it, it toggles to Cancel button. What I would like to do is cancels all current selections when user taps Cancel. It should work just like Photo app. I know how to deselect a selected cell but I don't how to retrieve a collection of selected cells, so that I can iterate through it and deselect them. The following is my attempt, but as you can see, it only deselect one cell.
func deselectAll()
{
if let index = self.tableView.indexPathForSelectedRow{
self.tableView.deselectRowAtIndexPath(index, animated: true)
}
}
You can use the table view's indexPathsForSelectedRows property to get an array of selected NSIndexPaths. Loop over this array and deselect each one.
I have a uitable view and I want to perform didselectrow manually on button action; then next view controller is pushed. Take their a screen shot and get back. Again perfom this action till data source counts?
Any sample logic or objective c code ?
The scenerio is :
1. Click on UIButton to start didselectrow manually.
2. Index 1 of uitabel view is selected ; next view controller will be presented; here it takes a screenshot and then get back.
3. Then it shows next view controller as of uitable's 2nd indexpath.row; again takes screenshot and get pop to previous view controller.
4. This scenerio continues till all indexes view controller displayed and got thier screen shot
A very simple approach,if you want to do didSelect on UITableView manually then store your indexpath.row value in your Cell's Button Tag.
Now, in your button action call the didSelect of tableView as per button tag.
Demo Code:-
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:btn.tag inSection:0]
[self tableView:playListTbl didSelectRowAtIndexPath:indexPath];
I have created 5 views using Page view controller. Each view has 4 buttons. When I click any button, the tag of that button gets added to an array. Now, the situation is..Say, I opened view 1..I clicked a button..the button's tag gets added to the array. when I click another button in the same view, this button's tag also gets added to the array. The task is to remove the previously clicked button's tag from the array and only the latest one should persist. Any help?
Thank You
I suggest you to use a dictionary instead of array. That way you can easily replace the object related to a specific key.
[dictionary setObject:object key:somekey];
Add null objects intially in NSMutableDictionary to check whether button clicked or not
//number depends on numbers of view in page view controller
for(int i=0; i<[yourPageViewController.viewControllers; i++)
[yourMutDictionary setObject:[NSNull null] forKey:[NSString stringWithFormat:#"%d",i]];
UIButton's click event will be contain below lines of code
-(IBAction)btnClickedAction:(id)sender
{
UIButton *btnClicked = (UIButton *)sender;
NSUInteger index = yourPageViewController.pageControl.currentPage
[yourMutDictionary setObject:[NSString stringWithFormat:#"%d",btnClicked.tag] forKey:[NSString stringWithFormat:#"%i",index]];
}
you better keep the tag values in NSMutableSet object which will help you in avoiding duplicates.
you directly add button object to NSMutableSet and check if the button is available in NSMutableSet remove the button from NSMutableSet else add it to the NSMutableSet
NSMutableSet *set;
[set addObject:senderButton];
if([set containsObject:senderButton]) {
//set contains button remove that button
} else {
// set doesn't contains button add it
}
I have a label on the top of my view. After you enter a string into a text field on a different view, this string is saved into NSUserDefaults upon clicking a UIButton. This UIButton also segues into my UITabBarController. I want the label at the top of the shown tab to change to the string saved from the previous view. All I have at the moment is this.
-(void)viewWillAppear:(BOOL)animated
{
// Do any additional setup after loading the view.
self.prefs = [NSUserDefaults standardUserDefaults];
NSString *username = [self.prefs stringForKey:#"Username"];
self.userNameLabel.text = username;
}
This is in the viewcontroller.m file for the first tab in the tab bar controller.
The issue is that when the segue happens, the label is left blank; however, when I change to the second tab and back to the first, the label is not accurately changed. I'm sure it's a simple fix, it is just over my head.
I want to create a tableView or tabs that expands when user selects them. This is very commonly used in webpages using jquery.
you can check http://jqueryui.com/accordion/ It does exactly what i want to do in my ipad app. with horizontal tabs too http://jqueryui.com/tabs/
Can anyone tell me how to achieve this in my iPad app ? Or any pointers would be appreciated.
TIA
Sam
1.Use UITableView for first type of tab.
a) Use Header and Cell View in your desired format.
b) Hide and unhide cell view with some animation.
2.Use UISegementedControl for second type of tab.
a) Use function addTarget :
[self.mySegmentedControl addTarget:self action:#selector(segmentChanged) forControlEvents:UIControlEventValueChanged];
b) Implement segmentChanged :
- (void) segmentChanged:(UISegmentedControl *)paramSender{
//check if its the same control that triggered the change event
if ([paramSender isEqual:self.mySegmentedControl]){
//get index position for the selected control
NSInteger selectedIndex = [paramSender selectedSegmentIndex];
if (selectedIndex == 1 ) { // do required } and so on....
}
}
The best possible way is using the headerview to show the Master row and the tableview cells for showing the Details row.Write a touch event for the headerview and set it with the showing and hiding the cells ,with neat row animation.You need to keep the status of the opened and closed state of cell with an array of bools repesenting the no of masterview.