question about navigationController and pvc - iphone-sdk-3.0

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
/*
When a row is selected, set the detail view controller's detail item to the item associated with the selected row.
*/
//detailViewController.detailItem = [NSString stringWithFormat:#"Row %d", indexPath.row];
ABPersonViewController *pvc = [[ABPersonViewController alloc] init];
pvc.displayedPerson = [searchArray objectAtIndex:[indexPath row]];
[[self navigationController] pushViewController:pvc animated:YES];
}
In my tableview, when a cell is clicked, the above code is executed a new view is pushed and the items (address, phone, etc) do nothing when touched.
How do I make it so that when the address is touched, Google Maps launches
If the phone number is touched, the phonecall is placed

Have a look at the following
http://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ApplicationEnvironment/ApplicationEnvironment.html#//apple_ref/doc/uid/TP40007072-CH7-SW26

Related

NSTableViewCell selectedRow number for IBAction click

I'm running into a simple problem but have yet to find an optimal solution. I have a view based NSTableView that is loading it's cell views from different xibs. My table view is dynamic and based on user input I will dynamically add and remove rows ultimately adjusting the table data source. Each one of my NSTableCellViews have a button in it and I link the IBAction click handler to the NSView that holds the table view. What I need to do is get the row number for the button that was clicked in the table view so I can process the logic. I am able to do this successfully in : tableViewSelectionDidChange:(NSNotification *)notification
Here is how I do it:
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
NSTableView *tableView = [notification object];
NSInteger selectedRow = [tableView selectedRow];
}
This works perfectly for a user actually clicking the row. Now when I move the NSButton IBAction and link it in the NSView as follows:
- (IBAction)buttonClickHandler:(NSButton *)sender {
NSInteger selectedRow = [self.tblView rowForView:sender];
NSLog(#"%ld", (long)selectedRow);
}
I based this approach from this selected answer.
I also tried this:
- (IBAction)buttonClickHandler:(NSButton *)sender {
id representedObject = [(NSTableCellView *)[sender superview] objectValue];
NSLog(#"%#", representedObject);
}
//My configuration
- (void)configureView {
[self.view setFrame:[self bounds]];
[self addSubview:self.view];
[self.view setWantsLayer:YES];
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
self.tblView.delegate = self;
self.tblView.dataSource = self;
[self.tblView setIntercellSpacing:NSMakeSize(0, 0)];
[self.tblView registerNib: [[NSNib alloc] initWithNibNamed:#"ParentCellXib" bundle:nil] forIdentifier:#"ParentCell"];
[self.tblView registerNib: [[NSNib alloc] initWithNibNamed:#"ChildCellXib" bundle:nil] forIdentifier:#"ChildCell"];
[self.tblView registerNib: [[NSNib alloc] initWithNibNamed:#"HeaderCellXib" bundle:nil] forIdentifier:#"HeaderCell"];
}
But the represented object returns null. If it's worth mentioning, I've set my File's Owner as the View that holds the tableView so I can link the IBAction and I've subclassed the TableCellView to a different class. However, I don't think this is part of the problem as far as I can see. Is there a simple solution to reliably give me the selectedRow number based on a button click in that cell? Both approaches I tried above return -1 and null respectively.
I would set the row in NSButton's tag property:
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
SomeTableCellView *cell = [tableView makeViewWithIdentifier:#"cell" owner:self];
if (cell == nil) {
cell = // init some table cell view
cell.identifier = #"cell";
}
cell.button.tag = row;
[cell.button setTarget:self];
[cell.button setAction:#selector(buttonAction:)];
}
- (IBAction)buttonAction:(id)sender {
NSLog(#"row: %d", sender.tag);
}
Try This
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
yourCustomeCell *aCell;
NSString *aStrIdentifier = #"yourIdentiFier";
aCell = (yourCustomeCell *)[tableView dequeueReusableCellWithIdentifier:aStrIdentifier];
//you have to set your indexpath
objc_setAssociatedObject(aCell.btnUpload_or_Add, #"objBtn", indexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[aCell.YourButton addTarget:self action:#selector(yourButtonActiontapped:) forControlEvents:UIControlEventTouchUpInside];
return aCell;
}
-(IBAction)yourButtonActiontapped:(UIButton *)sender{
NSIndexPath *aIndPath = objc_getAssociatedObject(sender, #"objBtn");
NSLog(#"row:%#",aIndPath.row);
}
also you have to import #import <objc/runtime.h>
another way to get row in IBAction is TAG but objc is better option insted of TAG.
Create a subclass of UIButton and add a property for NSIndexPath for the button. Use this button in cellForRowAtIndexPath method. assign the index path of the cell to that of index path of the button.
On Tap, get the index path from its sender. In your case index path of that button.

How to pull Array from tableview to detail view?

I am using a dictionary to populate tableview with objects. table view cells are set to subtitle, two arrays in this dictionary are used to display data for tableview (title and sub). Now I'm interested how to send the rest of arrays in this dictionary to the next "detail view". I am using Parse to store this dictionary data. I simply need to show 3 more fields from the same database on my details when cell is activated. Thanks
If I understand your question, you want to show the rest of the data of the other arrays in your detail view.
Use the delegate method of the table view "didSelectRowAtIndexPath". Here allocate the controller you want use as Detail View in your Controller, assign to this Detail Controller the info you got taking the index of the cell touched, and make a push to this Detail View.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailController *detailVC=[[UIControllerView alloc] initWithNibName:#"DetailController" bundle:nil];
detailVC.textFieldOne.text=[self.arrayOne objectAtIndex:indexPath.row];
detailVC.textFieldTwo.text=[self.arrayTwo objectAtIndex:indexPath.row];
detailVC.textFieldThree.text=[self.arrayThree objectAtIndex:indexPath.row];
[self.navigationController pushViewController:detailVC animated:YES];
}
I seen you are using Storyboards.
Try to asign with Key-Value-Coding the value on prepareForSegue:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.destinationViewController isKindOfClass: [BookDetailViewController class]]) {
BookDetailViewController *destination = segue.destinationViewController;
SEL selector = NSSelectorFromString(#"setFile:");
if ([destination respondsToSelector:selector]) {
NSIndexPath *indexPath = [self.bookstableview indexPathForCell:sender];
PFObject * object = [Booksarray objectAtIndex:indexPath.row];
PFFile *file = [object objectForKey:#"BooksTableView"];
[destination setValue:file forKey:#"file"];
}
}
}
And try to delete the call to deselectRowAtIndexPath: before you perform the segue on your didSelectRow. If you don't want show the row selected, you can edit that on the Attributes Inspector disabling "Show selection on touch" of your Table View in your Storyboard view.
To show the image from a PFObject:
PFQuery *query = [PFQuery queryWithClassName:#"nameOfParseClass"];
NSArray *objectsPFFounded=[NSArray arrayWithArray:[query findObjects]];
int i=0;
while (i<count){
PFFile *ImageFile = [objectsPFFounded objectAtIndex:i][#"nameOfImageObjectKey"];
[ImageFile getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
//HERE YOU GOT THE IMAGE
UIImage *image=[UIImage imageWithData:imageData]
}
}];
i++;
}

not able to click the search bar tableview cell

I've got a tableview containing array of names. The search bar works perfectly filtering the names in the table view.
The problem is the didSelectRowAtIndexpath is not getting fired when clicking the search tableview cell. Could you help me out?
What is the thing that I'm missing? Should I include any special delegate to involve search tableview cell click.
Below is the image and code.
-(void)search
{
nameArray = [[NSMutableArray alloc] init];
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 160, 44)];
searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
self.tableViewFriendsList.tableHeaderView = searchBar;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller
willShowSearchResultsTableView:(UITableView *)tableView
{
[tableView setRowHeight:70];
[tableView reloadData];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.tableViewFriendsList) {
NSString *friendsID =[[[self.friendsDictionary objectForKey:#"data"] objectAtIndex:indexPath.row] objectForKey:#"id"];
[[FacebookHelper sharedFacebookHelper] postOnWallWithDelegate:self andID:friendsID];
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(#"I ve come here");
NSString *friendsID =[friendsListIdArray objectAtIndex:indexPath.row];
[[FacebookHelper sharedFacebookHelper] postOnWallWithDelegate:self andID:friendsID];
}
}
You forgot to set
searchController.searchResultsDelegate = self;
I do something in one of my projects that may be of assistance:
// add gesture to detect when table view is being tapped so that keyboard may be dismissed
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(dismissKeyboard)];
gestureRecognizer.cancelsTouchesInView = NO;
[self.tableView addGestureRecognizer:gestureRecognizer];
Moreover I am wondering why you have a search bar within a table cell. Would you mind posting a screen shot of it in your app? I am afraid you may be doing more work than is necessary.

How to display the detail of an array's index in a new view?

I have table view which is populated from an array grabbed from a url. I set the title of each row with a few characters from the string object of array and when the cell is clicked a new view is pushed. In this new view i have a UILabel. At this point what i want is, to set the title of this lable with the full string of that index..
Here is my code:
NSDictionary *object=[[NSUserDefaults standardUserDefaults]objectForKey:#"savedMessage"];
NSArray *array= [object valueForKey:#"message"];
cell.textLabel.text= [array objectAtIndex:indexPath.row];
and by the following code i push new view:
messageDetail *detailViewController = [[messageDetail alloc] initWithNibName:#"messageDetail" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
detailViewController.title=#"Message Detail";
[detailViewController release];
What i want is, how can display any result(detail) of the array at its own index?
(for example, when i clicked the 5. row i want my detailViewController's label be set as the 5. object of array)
You create a function in messageDetail.m called like so:
- (void)updateLabelWith:(NSString *)labelString{
label.text = labelString;}
And then you call it in the didSelectRowAtIndexPath in tableViewController
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *labelString = [data objectAtIndex:indexPath.row]; // data is an NSArray of Strings
[detailViewController updateLabelWith:labelString];
[self.navigationController pushViewController:detailViewController animated:YES];}

Objective-C TableView Select Item Troubles

I'm having trouble having my app respond when an Item is selected in the table view. I'm running everything from my app delegate (the table functions that is like dataSource and TitleForHeaderAtSection etc) which are all being called fine. However it is not calling my selection method when I tap on a item in the list. I even put a NSLog to see just in case.
Here's my code: (its quite long and extensive and I know theres crap in there that doesn't need to be there but I put all of it just in case you needed it...)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(#"Selected Row.", #"");
//Get the selected country
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSDictionary *dictionary = [data objectAtIndex:indexPath.section];
//NSArray *array = [dictionary objectForKey:#"My Wishlists"];
//NSString *selectedWishlist = [array objectAtIndex:indexPath.row];
//Initialize the detail view controller and display it.
WishlistDetailView *dvController = [[WishlistDetailView alloc] initWithNibName:#"WishlistDetailView" bundle:[NSBundle mainBundle]];
dvController.selectedWishlistId = [wishlistids objectAtIndex:indexPath.row];
NSLog(#"Selected row with wishlist id: %#", dvController.selectedWishlistId);
[[self navController] pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
The code compiles with NO errors.
Thanks for your persistant help!!
Christian Stewart
(by the way both of the selection allowed checkboxes are checked in Interface builder.)
tableView:didSelectRowAtIndexPath: is a UITableViewDelegate method. Is you controller the delegate of the table view?