I am passing values from table view to collection view controller using SwReveal view controller. when I click a cell in collection view I stored the collection view cell's index path. But when I select a table and pass a value to the index path collection view. The cell not displaying the value. It is null... here is my code
-(void)viewWillAppear:(BOOL)animated{
text=seltext;
NSLog(#"text %#",text);
**// HERE I AM GETTING VALUES FROM TABLE VIEW CONTROLLER**
self.displayindex=Viewindex;
NSLog(#"self dispaly %#",Viewindex);
**// HERE I AM GETTING INDEX PATH OF SELECTED COLLECTION CELL**
Cell *cells = (Cell *)[collectionData cellForItemAtIndexPath: self.displayindex];
cells.subjectLabel.text=#"djhfkjdshfjkhd";
cells.cellView.backgroundColor=[UIColor greenColor];
NSLog(#"cell is %#",cells);
NSLog(#"text %#",text);
**// CELL IS NULL HERE AND NOTHING IS DISPLAYING EVEN IF I PASS THE CELL FRO ITEM INDEXPATH**
}
Related
I have a tableview which has multiple rows , in each row I have collection view with multiple items that scrolls horizontally . Now I want to get the exact tableview row index whose collection cell's item i have clicked.My tableview delegate methods are in ViewController.m file and collection cell delegate methods are in TableCell.m file. And on click collection view item only collection view didSelectItemAtIndexPath:(NSIndexPath *)indexPath is called in which i am not able to get the tablview row index. Please help me with some suggestions how to get the table row index.
I have a TableView with custom cell with a CheckBox, A label and a TextField. I want to get label text and TextField text of all the cells that I have CheckBox checked. How can I achieve it. whenever I scroll the TableViewCell index changed so I am not able to use rowAtIndexPath.
From my point of view, you will have to use array to keep track of which cells are checked. So declare NSMutableArray *checkedCells; variable and initialize it. In your didSelectRowAtIndexPath write following lines :
UITableViewCell *cell= [tableView cellForRowAtIndexPath:indexPath];
if (cell.radioChecked)
{
/*Create a object with textField and label value here.and add that object in checkedCells here*/
}
else
{
/*remove regarding cell object from checkedCells here*/
}
This way you will get properties of cells which are checked.
I have a tableView with custom cells.
Tableview is empty.
I have "+" button which add my custom cell with label and textfield
Question: how can i save to mutable array textfield.text of all tableview cells when user pressed "+" button
Code of a "+" button here...
- (IBAction)addButtonPress:(UIBarButtonItem *)sender {
MYCustomTableViewCell *nextCell =[self.myTableViewProperty dequeueReusableCellWithIdentifier:cellId];
if (!nextCell) {
nextCell = [[MYCustomTableViewCell alloc] init];
}
MYCustomTableViewCell *previousCell =[self.myTableViewProperty dequeueReusableCellWithIdentifier:cellId];
NSIndexPath *saveTextIndex = [NSIndexPath indexPathForItem:myCustomCellCount inSection:1];
// -- i can't get my customCell.textField.text
previousCell = [self.createTableView cellForRowAtIndexPath:saveTextIndex];
NSLog(#"%#", previousCell.textField.text); ////- its null=(
[cellArray addObject:nextCell];
[self.myTableViewProperty reloadData];
}
Add tag property to your textField that equals to you indexPath then you can simply access your textfields by their tag property.
Example:
Creating your new customCell
cell.textField.tag = indexPath.row;
Getting your cell's textField
MYCustomTableViewCell *previousCell =[self.myTableViewProperty cellForRowAtIndexPath:indexPath];
UITextField *txtF = (UITextField*)[previousCell viewWithTag:myCustomCellCount];
Please, have a look at the documentation UITableViewDataSource Protocol Reference before beginning. This link might be usefult as well. UITableView is just to display the content of your model (called datasource). So when addButtonPress: is called you should insert a data object into your datasource (e.g. an array) and tell the table view to reload it's content. In almost all cases dequeueReusableCellWithIdentifier: is ONLY called in tableView: cellForRowAtIndexPath:. That's where a new table view cell representing your datasource's data objects is created. And there's no need to store the table view's cells in an array because that's done by the table view itself. When the user is done pressing the button you just iterate over your datasource array and read it's data objects.
I have created a five column (text boxes) cell (row) in table view controller with an option of add button. When a user clicks on add button, a new row (cell) with five column (text boxe) is added in a table view controller with null values. I want that when user fills the text boxes the data should get saved in database or if he changes any data in previous text boxes also it get saved.
this is my save btn coding..
- (IBAction)btn_save:(id)sender
{
NSInteger noOfRow=[(NSSet *)[projectObject valueForKey:#"rs_project_Input"] count];
NSLog(#"Save Btn: No of rows for saving %d",noOfRow);
for (row1=0; row1<noOfRow; row1++)
{
NSLog(#"Row is %d",row1);
path = [NSIndexPath indexPathForRow:row1 inSection:0];
Input_Details *inputDetailsObject1=[[self sortInputs] objectAtIndex:path.row];
/*
Update the input details from the values in the text fields.
*/
EditingTableViewCell *cell;
cell = (EditingTableViewCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row1 inSection:0]];
inputDetailsObject1.mh_Up= cell.cell_MH_up.text;
inputDetailsObject1.mh_down=cell.textField.text;
NSLog(#"Saving the MH_up value %# is saved in save at index path %d",inputDetailsObject1.mh_Up,row1);
[masterController saveContext];
}
[self.tableView reloadData];
}
My problem is that the code is not helping in saving the data. Plz help.
Thanks
You try to use the table view cells as a data source, which will not work (apart from being a bad design). The problem is that
[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row1 inSection:0]]
returns nil if the cell at that row is currently not visible. (A table view allocates only cells for the visible rows and reuses these cells as you scroll up or down.)
You have to track changes to the text fields immediately, e.g. by implementing a textFieldDidEndEditing: delegate function, and store the changed text in your data source.
I have a tableview which loads data for an sqlite database and displays them in sections.
Its cell of the tableview has three labels for displaying text.
My question is can I get the text value of a label in the selected cell in prepareForSegue, so i can pass it to the detail view?
Yes, you can do this. You should set the tag property on each of the UILabels in your table view's prototype cell (you can do this in the storyboard) so you can identify them in your prepareForSegue: code.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// sender is the table view cell that was selected
UITableViewCell *cell = sender;
// get the text of the label in the cell with tag 0
NSString *firstLabelText = [[cell.contentView viewWithTag:0] text];
// now use that text to set a property on your segue's destinationViewController...
}