How can I have more than 2 values held by my table view cell? What I want to happen is when I click a cell in my table view, it will pass 3 values to the next view. But I can only get two values (name, address) because they are contained in the textlabel and detailtextlabel but the (phone) is not being showed in my cells, only name and address.
If u want to display more value in cell the create custom cell.
Option is use NSMutableArray with like below and show all values in custom cell:
NSMutableArray *arrValues = [[NSMutableArray alloc] initWithObjects:[NSArray arrayWithObjects:"Value1","Value2","Value3"],nil];
Add as many array into arrValues.
Now when tableViewDidSelectAtRow 's method: pass this array to next controller
NSArray *arrPassing = [arrValues objectAtIndex:indexPath.row];
create a custom cell for the tableview cell
Related
Say i have a list of food table and display all food categories such as american, ltaliano and japanese. then when i click american it will show list of american food such as hamburgers. please help.
There two ways to store data as
1) In instance variable, NSDictionary
NSDictionary *dict = #{#"american":#[#"hamburgers",#"french fries"], #"ltaliano" : #[#"Insalata caprese",#"Pasta e fagioli"], #"japanese": #[#"Udon noodles",#"Donburi rice bowl"]};
Load your table using NSDictionary's [dict allKeys] method and when you click on a row, get keyName from NSDictionary's and pass values for this key into the next UIViewController
2) Store your data in the SQLite local database with FoodCategory(have all food categories) and FoodDetails(food category and its foodName) Table. In first UIViewController, to display lists of food, get foodCategories from the FoodCategory table and store it into NSArray. Using this NSArray load your table. When you click on any row pass selected foodCategory to the next UIViewController and in this to get its foodNames, write SELECT query to fetch all records from FoodDetails table for selected foodCategory.
For tutorial:
Basic UITableView tutorial1
Basic UITableView tutorial2
Hope this will help you.
I have a view based NSTable with ten or more rows and five columns. To populate data for this table, I have a dictionary of 5 arrays. So each dictionary object is for each column.
Now I need to get information when I click on any cell. I am using tableViewSelectionDidChange delegate to get notified on cell selection. Using this I can get only the [myTableView selectedRow] to get to know the row selected. How can I know which column was the row in. For ex: I select/click on 5th row in 3rd column. Now I need to know which column was it clicked on so that I can extract required object from the dictionary.
Any clues ?
You may override the mouseDown: event of your tableView and get the clicked column as:
- (void)mouseDown:(NSEvent *)theEvent
{
NSPoint globalLocation = [theEvent locationInWindow];
NSPoint localLocation = [self convertPoint:globalLocation fromView:nil];
NSInteger clickedCol = [self columnAtPoint:localLocation];
[super mouseDown:theEvent];
}
or you may use NSTableView delegate method:
tableView:didClickTableColumn:
For reference check:
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSTableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSTableViewDelegate/tableView:didClickTableColumn:
I am making an app where I'll have a tableview with an 'add' button in the navigation bar, and this 'add' button creates a new row, but the problem is I can't figure out how to give rows unique names. To let the user decide the name, I have included an alert with a plain text field. The user should then write the name in the field and the new row will then be called that. But how do I do that?
I have used the tableview template provided in Xcode, which give each row a new name according to the clock they added a new row. I'll just want a alert to pop up first and then let the user type the name for the new row.
You have to identify each row somehow. One way is to use the index in the table as the identifier. I guess your adding the row to a NSArray which is mapped to the table rows or something similar, so you know the index of the new row. You only have to update the row of that index using this method on your UITableView:
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
Assuming you have only one section, your array is called 'arrayWithRowsData' and you put the new row at the end, you can create the index path with:
int newRowIndex = [arrayWithRowsData count] - 1;
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:0];
Hope it helps.
I have a NSTableView with 3 columns. I can sort using any of the colunms by clicking on the column header. Here is my issue though: I am presorting the array and then loading it in NSTableView so the initial TableView is already sorted by the values in one of the 3 columns. Now when I click on the column headers, i can resort and the small ascending/descending image ( triangle) appears indicating how the sort order is. What I want is, to be able to display this ascendingimage triangle in the column header right at the start when the NSTableView is loaded the first time, for the column based on which I have already sorted the Array. Thanks in advance :)
Thanks Peter and cb160. So I added this in my refreshList method:
The *lastColumn parameter has the right identifier if i display it using NSLog, but still that triangle image does not get loaded when the table loads data the first time. Is there something I am missing here ?
My table View is setup like this:
-(IBAction)refreshList:(id)sender
{
//setup array here and sort the array based on one column. This column has
identifier 'col1' and it works as expected
// trying to set the sortindicator image for the column here
NSTableColumn *lastColumn;
lastColumn = [aTableView tableColumnWithIdentifier:#"col1"];
[aTableView setIndicatorImage:[NSImage imageNamed:#"NSDescendingSortIndicator"]
inTableColumn:lastColumn];
[aTable reloadData];
}
- (int) numberOfRowsInTableView:(NSTableView *)aTable
{ // return count of array
}
- (id)tableView:(NSTableView *)aTable objectValueForTableColumn: (NSTableColumn *)
tableColumn row:(int)row
{
//set up arrays here to load data in each column
}
- (void)tableView:(NSTableView *)aTableView sortDescriptorsDidChange:(NSArray
*)oldDescriptors
{
//sort here when column headers are clicked
}
You can use the -setIndicatorImage:inTableColumn: method on NSTableView to do this.
You can use the strings NSAscendingSortIndicator and NSDescendingSortIndicator to use the built in images (with UIImage's +imageNamed: method.)
You can get the NSTableColumn * parameter for this method using the -tableColumnWithIdentifier: method on NSTableView. Set the idenitfier in the column using the identifier attribute in Interface Builder (see below)
i have NSTableView bound to an NSArrayController. in my model i have a BOOL field. i'm trying to bind that value to the column. it displays correctly (1 where value is YES and 0 where value is NO), but it's readonly. =( when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. column is editable.
i can successfully bind it with IB -- i just bind it as usual and all works. but i can't do the same programmatically =(
that's how column is created and added:
NSTableColumn *column = [[[NSTableColumn alloc] initWithIdentifier:#"ok"] autorelease];
[column setEditable:YES];
[[column headerCell] setStringValue:#"OK"];
[column bind:#"value" toObject:self.arrC withKeyPath:#"arrangedObjects.ok" options:nil];
[table addTableColumn:column];
i have a problem only with BOOL values, if i bind the same column to some other field (just changing keyPath) all works fine.
it's readonly =(. when i'm trying to edit a value i can't submit it -- when i press enter nothing happens, setter is never invoked. column is editable.
And then, in your code snippet:
[column setEditable:NO];
Your column is not editable. That's why editing doesn't work. Change NO to YES.
By the way: Is there a reason you're displaying this value as text and not a checkbox?
You need to bind the table column, not the cell.
What is bound to arrC which I am assuming is your array controller?
Is arrC bound to an array? What's are the objects in the array bound to the controller? Coredata entities? NSMutableDictionaries?
You need a value transformer, specifically NSNegateBooleanTransformerName. Google for Apple's "Value Transformer Programming Guide"