I have A Table View Controller containing names (as example A, B, C, etc,,,).
If I pressed on one cell, it should be shifting to another B View Controller with the 2 numbers (a, b).
and on the name cell, it should appear the value of c = (a + b) in the subtitle.
On B class, i create a protocol in order to send to A a NSDictionary.
and from A, i can access these Data without any problem from A
I am just cannot solve how to insert the value of c in the subtitle of the same cell which I clicked.
for example, when i press on A name1, i switch to second view controller, So, i put values for a = 2 and b = 6 and click on save, I got the value c = a + b = 8.
I want to have name1 and under the value of 8.
I tried to reload data for table view, but didn't work.
Where shall I write some codes in order to make the subtitle with the value c appear.
Try this
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = #"text";
cell.detailTextLabel.text = #"description text";
}
Related
I have NSTableview with N rows and two columns (column_A and column_B).
I want cycling on rows, i try so :
IBOutlet id myTableView;
NSTableColumn *column_A = [myTableView tableColumnWithIdentifier:#"A"];
NSTableColumn *column_B = [myTableView tableColumnWithIdentifier:#"B"];
int nr = [myTableView numberOfRows];
for (int i = 0; i<nr; i++) {
NSString *a = [[column_A dataCellForRow:i] stringValue];
NSString *b = [[column_B dataCellForRow:i] stringValue];
... (other code)
a = nil;
b = nil;
}
But I get same values,
for i = 0 I get a = test1 and b= test2
for i = 1 I get a = test1 and b= test2
...
for i = nr -1 I get a = test1 and b = test2
Where is the error ?
-[NSTableColumn dataCellForRow:] returns the prototype cell that is used to show the value at that column and row. This prototype cell can be reused for multiple rows in the same column, so you cannot rely on it having the specific value shown at a given row.
In general, if you want to enumerate the values shown by a table view, you iterate over its data sourceāan NSTableViewDataSource-conforming instance, which can be obtained via -[NSTableView dataSource], or an NSArrayController instance bound to contents if you are using bindings.
If for some reason you cannot or do not want to use the data source, you should use -[NSTableView preparedCellAtColumn:row:] instead. This method makes sure that the cell is populated with the data source/content value for a given column and row.
I have the following code that populates a UIPickerView with the string value that was previously selected stored in the variable "preValue."
NSUInteger currentIndex = [arrayColour indexOfObject:preValue];
[ColourAndShadePicker selectRow:currentIndex inComponent:0 animated:YES];
The problem is that it doesn't seem to be matching the value exactly when there are spaces involved.
For instance if the 3 options are
Red
Green 1
Green 2
and the user selects Green 2, the Green 2 value is stored but on re-populate it's selecting Green 1 and not Green 2.
I think it has something to do with the spaces, and picking the first similar option?
Any ideas how to solve?
I'm unable to use the row number and need to match the string exactly.
EDIT:
To populate the array in the first place I'm using the following:
arrayColour = [[NSMutableArray alloc] init];
for (int i = 0; i < [substrings count]; i++)
{
//parse out each option (i)
NSString* companyoption = [substrings objectAtIndex:i];
//add as option to component
[arrayColour addObject:companyoption];
}
Thanks!
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
I'm trying to get a table layout as shown below working with view-based NSTableViews that have been introduced in Lion.
There were multiple approaches described for cell-based NSTableViews, e.g. Mimic the artwork column, but these don't really apply for view based table views.
The idea is that the table gets populated by an array of objects, in one (or more) column spanning rows indicating that objects share some data in common. numberOfRowsInTableView: returns to total number of items (19 in the case of the attached image).
Has anyone tried something like this?
Layout
I was able to do this by using two separate NSTableViews that have their NSScrollView's scrolling synchronized. To learn how to synchronize multiple scroll view's (with the exact subclass code) read Scroll View Programming Guide for Mac - Synchronizing Scroll Views
I have groupTableView that has a single column and shows the views that represent the group. I also have itemTableView that has columns representing the items of the group. I use the same delegate/datasource methods with if-else-statements to check which NSTableView is being used and respond accordingly with the proper # of rows, cell view, etc.. Additionally, I implement the following delegate method to adjust the group table view's row height to be equal the sum of the item row heights of the rows in the group:
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
if (tableView == self.groupTableView) {
NSUInteger firstRowIndexForGroup = ...;
NSUInteger lastRowIndexForGroup = ...;
CGFloat groupHeight = 0.0;
for (NSUInteger currentRowIndex = firstRowIndexForGroup; currentRowIndex <= lastRowIndexForGroup; currentRowIndex++) {
groupHeight += [self.itemTableView rectOfRow:lastRowIndexForGroup].size.height;
}
return groupHeight - [self.itemTableView intercellSpacing].height;
} else {
return self.itemTableView.rowHeight;
}
}
You must also call -noteHeightOfRowsWithIndexesChanged: every time the table view needs a group view because the height changes according to the number of rows in the group.
- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
if (tableView == self.groupTableView) {
GroupRowView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
// configure view
[tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
return view;
} else {
ItemRowView *view = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
// configure view
return view;
}
}
I disabled row selection and horizontal and vertical scroll bars on the group table view. I also made the horizontal grid solid for both table views. Finally, I position the group table view directly next to the item table view with no gap in between so it appears as if it's simply another column in a single table view. The result is a flawless implementation that has zero lag between the table views. To the user, it appears as if it's a single table view.
Could you not use an NSOutlineView instead? It's specifically designed to have grouping support.
Right now I have a table with a number of PDFs listed. From the table the user can select a PDF and it will be displayed in the view. Right now when I select and item from the table it should change the detailView's detailItem to the item in the row I selected, in addition change the variable i to the selected row number.
Here is what my DidSelectRowAtIndexPath method looks like:
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
affirmaPDFViewController.detailItem = [NSString stringWithFormat:#"%#", [listOfPDF objectAtIndex:indexPath.row]];
affirmaPDFViewController.i = indexPath.row;
NSLog(#"%d", indexPath.row); //returns the proper value
NSLog(#"%#", [listOfPDF objectAtIndex:indexPath.row]); //returns the proper value
//NSLog(#"%d", affirmaPDFViewController.i); //DOES NOT return the proper value
//NSLog(#"%#", affirmaPDFViewController.detailItem); //DOES NOT return the proper value
}
for the first two NSLog's, they display the proper information, however when i check the last two they come out with affirmaPDFViewController.i = 0 and affirmaPDFViewController.detailItem = null. When i need the affirmaPDFViewController.i= indexPath.row, and affirmaPDFViewController.detailItem = the item in the row I selected.
Anyone know why they aren't coming out with the proper values?
Thanks in advance!
Your instance of affirmaPDFViewController is nil. Check the method where it's created, and remember you can set a breakpoint in the debugger to see if it's a valid object or not.