I've ran into a problem. I have a TableView that I have created programmatically which does not display the TextView that I have added corresponding to the rows of TableView. I cannot find a solution to this on Stack Overflow.
#import "MasterTableViewController.h"
#interface MasterTableViewController ()
#end
#implementation MasterTableViewController
-(NSMutableArray *)numbers {
if(!_numbers)
{
_numbers = [[NSMutableArray alloc] init];
}
return _numbers;
}
-(NSMutableArray *)subtile {
if(!_subtile)
{
_subtile = [[NSMutableArray alloc] init];
}
return _subtile;
}
- (void)viewDidLoad
{
//Adding Titles
[self.champions addObject:#"1"];
[self.champions addObject:#"2"];
//Adding subtitles
[self.subtileChamps addObject:#"One"];
[self.subtileChamps addObject:#"Two"];
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.numbers.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
cell.textLabel.text = self.numbers[indexPath.row];
cell.detailTextLabel.text = self.subtile[indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
#end
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle: reuseIdentifier:]
}
You should init your cell
And... You have a common way for initiate your variables. This one should be suitable for you. That method calls before all others and you can initiate your variables here:
-(id)initWithStyle:(UITableViewStyle)style
{
if (self = [super initWithStyle:style])
{
someArray = [NSMutableArray array]; //init the array
}
return self;
}
Related
I'm learning how to make a contact using TableView and navigation controller. I have done the first view page with some cells, but I have some problem with showing the cells on the detail view page of each cell from first view.
when tap the Group A, Group B, Group C on first view page, it goes to the detail view of each cell, it should show cells named A1 A2 A3, B1 B2 B3 or C1 C2 C3 according to my code on detail view page. but it display nothing.
Hope someone can give me some advises, thank you so much!
FirstViewController.m
#implementation FirstViewController
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSections(NSInteger)section{
return [self.contactArray count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *Celldentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier];
if (cell == NULL) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier];
}
cell.textLabel.text = [self.contactArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.myTableView = [self.contactArray objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:#"To Second View Segue" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"To the second view"]){
NSIndexPath *indexpath = [self.myTableView indexPathForSelectedRow];
self.contactArray = [self.contactArray objectAtIndex:indexpath.row];
SecondViewController *vc = segue.destinationViewController;
vc.memberName = [self.contactArray objectAtIndex:indexpath.row];
vc.title = vc.memberName;
}
}
- (void)viewDidLoad {
[super viewDidLoad];
self.contactArray = [[NSMutableArray alloc]initWithObjects:#"Group A",#"Group B",#"Group C", nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
SecondViewController.m
#implementation SecondViewController{
NSArray *groupA;
NSArray *groupB;
NSArray *groupC;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if([self.memberName isEqualToString:#"groupA"]){
return [groupA count];
}
else if([self.memberName isEqualToString:#"groupB"]){
return [groupB count];
}
else if([self.memberName isEqualToString:#"groupC"]){
return [groupC count];
}
return 0;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *Celldentifier = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Celldentifier];
if (cell == NULL) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Celldentifier];
}
if([self.memberName isEqualToString:#"groupA"]){
cell.textLabel.text = [groupA objectAtIndex:indexPath.row];
}
if([self.memberName isEqualToString:#"groupB"]){
cell.textLabel.text = [groupB objectAtIndex:indexPath.row];
}
if([self.memberName isEqualToString:#"groupC"]){
cell.textLabel.text = [groupC objectAtIndex:indexPath.row];
}
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
groupA = [NSArray arrayWithObjects:#"A1",#"A2",#"A3",nil];
groupB = [NSArray arrayWithObjects:#"B1",#"B2",#"B3",nil];
groupC = [NSArray arrayWithObjects:#"C1",#"C2",#"C3",nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
first view
detail view but nothing displayed
Have you set the delegate and datasource of tableview?
If Yes, check if the datasource methods (numberOfRowsInSection:) are called after you do
groupA = [NSArray arrayWithObjects:#"A1",#"A2",#"A3",nil]; in viewDidLoad method.
Can someone help me? I've been following along with Apple's official Objective C tutorial (the one that has us create a To Do List).
I'm stuck at the part where tapping the cell item displays/removes a checkmark. It's not happening.
Here's my implementation file if someone could take a look?
I've really tried my best to solve where I went wrong. I swear I tried my best to figure out everything on my own before posting here. Please, any help would be greatly appreciated!!
Thank you!
EDIT: So i put a breakpoint in my didSelectRowAtIndexPath method. It was not triggered when I tapped a table item, so it's not getting called when I tap items, right? Where do I look next?
//
// ToDoListTableViewController.m
// ToDoList
//
// Created by Kevin Zagala on 9/1/14.
// Copyright (c) 2014 Kevin Zagala. All rights reserved.
//
#import "ToDoListTableViewController.h"
#import "ToDoItem.h"
#interface ToDoListTableViewController ()
#property NSMutableArray *toDoItems;
#end
#implementation ToDoListTableViewController
- (IBAction)unwindToList:(UIStoryboardSegue *)segue
{
}
- (void)loadInitialData {
ToDoItem *item1 = [[ToDoItem alloc] init];
item1.itemName = #"Buy milk";
[self.toDoItems addObject:item1];
ToDoItem *item2 = [[ToDoItem alloc] init];
item2.itemName = #"Buy eggs";
[self.toDoItems addObject:item2];
ToDoItem *item3 = [[ToDoItem alloc] init];
item3.itemName = #"Read a book";
[self.toDoItems addObject:item3];
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.toDoItems = [[NSMutableArray alloc] init];
[self loadInitialData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.toDoItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#pragma mark - Table view delegate
- (void)tableview:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
[tableView reloadRowsAtIndexPaths:#[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
#end
try this ..
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
ToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
try reloading whole tableview,
what u are doing should work, i tested your code by putting a dummy object with boolean value, it worked for me,
Note Both reloading the whole tableview and reloading the selected cell will work, only u are setting the correct boolean value
- (void)tableview:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
ToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
// [tableView reloadRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationNone]; //comment this
[tableView reloadData]; //add this
}
I feel like this is a fairly easy question, but I've tried for hours and can't seem to get it. I'm trying to create an app that calculates different equations that are critical to my job. Essentially, I've grouped the calculations into categories using nested TableViewControllers. This part works.
The part I am trying to figure out is how to push to a UIViewController so I can actually have the user enter data to do the calculations. For some reason I can't seem to get it to work. I am using Xcode 5 and am using Storyboards.
Really sorry for the long post. I've also included a screenshot of the storyboard at the following link: http://imgur.com/0oSxsR1
code below:
Root TableViewController Code (RootTableViewController.m)
#import "RootTableViewController.h"
#import "calculatorTableViewController.h"
#interface RootTableViewController ()
#end
#implementation RootTableViewController{
NSArray *calculatorOptions;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
calculatorOptions = [NSArray arrayWithObjects: #"General", #"Digital", #"Print", #"Television", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [calculatorOptions count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"CalculatorCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [calculatorOptions objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"calculatorDetails"]){
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
calculatorTableViewController *destViewController = segue.destinationViewController;
destViewController.calculationType = [calculatorOptions objectAtIndex:indexPath.row];
destViewController.title = destViewController.calculationType;
}
}
#end
Secondary TableViewController.h file (calculatorTableViewController.h)
#import <UIKit/UIKit.h>
#interface calculatorTableViewController : UITableViewController
#property (nonatomic, strong) NSString *calculationType;
#end
Secondary TableViewController.m file (calculatorTableViewController.m)
#import "calculatorTableViewController.h"
#import "CalculateGrpsHaveRF.h"
#interface calculatorTableViewController ()
#end
#implementation calculatorTableViewController{
NSArray *general;
NSArray *digital;
NSArray *print;
NSArray *television;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
general = [NSArray arrayWithObjects:#"Calculate GRPs (Have R & F)", #"Calculate Reach (Have GRPs & F)", #"Calculate Frequency (Have GRPs & R)", #"CPM to CPP", #"CPP to CPM", nil];
digital = [NSArray arrayWithObjects:#"Calculate Impressions (Have cost & CPM)", #"Calculate CPM (Have cost & impressions)", #"Calculate Cost (Have CPM and Impressions)", #"Calculate ASF", #"Calculate CPC/CPA/CPV", nil];
print = [NSArray arrayWithObjects:#"Calculate CPM", #"Calculate GRPs", #"Calculate CPP", nil];
television = [NSArray arrayWithObjects:#"Universe Estimates", #"Calculate GRPs", #"Calculate Spots", #"Calculate Average Rating", #"Calculate Total Impressions", #"Calculate CPP", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([_calculationType isEqualToString:#"General"]){
return [general count];
}
else if ([_calculationType isEqualToString:#"Digital"]){
return [digital count];
}
else if ([_calculationType isEqualToString:#"Print"]){
return [print count];
}
else if ([_calculationType isEqualToString:#"Television"]){
return [television count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"Calculator2Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if ([_calculationType isEqualToString:#"General"]) {
cell.textLabel.text = [general objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Digital"]) {
cell.textLabel.text = [digital objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Print"]) {
cell.textLabel.text = [print objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
else if ([_calculationType isEqualToString:#"Television"]) {
cell.textLabel.text = [television objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont systemFontOfSize:12];
}
return cell;
}
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"Calculate GRPs (Have R & F)"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
CalculateGrpsHaveRF *destViewController = segue.destinationViewController;
destViewController.Title = [general objectAtIndex:indexPath.row];
#end
If I understand correctly, you want calculatorTableViewController to perform segue to next view.
//when you select a row
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//perform a segue
if (indexPath.row == 1)
{
[self performSegueWithIdentifier:#"your_segue_identifier" sender:your_sender];
}
else if (indexPath.row == 2)
{
[self performSegueWithIdentifier:#"another_segue_identifier" sender:your_sender];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//prepare your segue here
}
here i have made a table class in which i have a list of 120 words, now i have to select minimum ten rows of the table for further precision.. please any one can guide me that how can i select more than 10 rows from table and save these value in specific array or somewhere else.. please help me out of it.
#implementation tableview
NSArray *myArray ;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myArray = [NSArray arrayWithObjects:
#"ad (a-d)",.......,Nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myArray count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [myArray objectAtIndex:indexPath.row]; //=#"ASDF" works.
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
}
#end
For multiple cell selection in your table add this code inside didSelectRowAtIndexPath: method. For saving selection values, create an iVar NSMutableArray and add the newly selected object inside didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)path {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
One quick idea that come into mind is, as soon as you select a row/cell, save the values in a collection object (array, dictionary), and keep on adding.
Delete from the collection if you deselect the row/cell.
my tableview changes values when I scroll up or down. It seems to use the same values from other parts of the table. I imagine its an error in my cell creation, here is the code.
Please tell me what I did wrong, thank you!
EDITED ADDED WHOLE CODE
//global indexpath to remember which cell tapped
NSIndexPath *globalPath;
#interface SearchViewController ()
#end
#implementation SearchViewController
//Load implementation once per launch
- (void)viewDidLoad
{
[super viewDidLoad];
[self linkInputTableToDelegate];
_temporaryResultsArray =[[NSMutableArray alloc]init];
_flurryArray=[[NSMutableArray alloc]init];
_numberOfSections=6;
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:NO];
[InputTable reloadData];
textFromUserDefaults=[[[HelperMethods alloc]init]getObjectUserDefault:#"textFiltered"];
[self addTextToFlurryArrayForFlurryAndSavedLists:_textFromUserDefaults];
}
-(void)viewDidDisappear:(BOOL)animated{
}
- (IBAction)searchButtonPressed:(UIButton *)sender {
self.tabBarController.selectedIndex = 1;
}
//Makes the input table respond to delegate table view methods
-(void)linkInputTableToDelegate{
_inputTable.dataSource=self;
_inputTable.delegate=self;
}
-(void)performSearch:(NSString*)text{
//do search
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
int numberOfRows=_numberOfSections;
//Rows for iPhone 4
if ([[UIScreen mainScreen]bounds].size.height==480) {
numberOfRows=numberOfRows;
//Rows for iPhone 5
}else if ([[UIScreen mainScreen]bounds].size.height==568){
numberOfRows=numberOfRows+1;
}
return numberOfRows;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//In reality groups are created with 1 row inside, this is to allow spacing between the rows
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kCellID = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
}
//Is the cell the same as the one clicked when going to ingredient filter
BOOL cellIndexPathSameAsSelected=[self isCellIndexSameAsPreviousClicked:indexPath];
cell.textLabel.textColor=[UIColor blackColor];
if (cellIndexPathSameAsSelected && _textFromUserDefaults!=nil) {
if (![cell.textLabel.text isEqualToString:_textFromUserDefaults]) {
cell.textLabel.text=_textFromUserDefaults;
[self performTextSearch:_textFromUserDefaults];
}
}
return cell;
}
//Compares the previous clicked cell with the cell now selected
-(BOOL)isCellIndexSameAsPreviousClicked: (NSIndexPath*)cellPath{
if (cellPath.row == globalPath.row && globalPath.section==cellPath.section) {
return YES;
}
else{
return NO;
}
}
- (void)updateTableViewWithExtraRow :(NSIndexPath*)rowSelected{
NSLog(#"number of sections =%i",_numberOfSections);
if (rowSelected.section == _numberOfSections) {
_numberOfSections ++;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText = [tableView cellForRowAtIndexPath:indexPath].textLabel.text;
[[[HelperMethods alloc]init]saveObjectToUserDefaults:cellText :#"textFiltered"];
globalPath = indexPath;
[self updateTableViewWithExtraRow:indexPath];
}
-(void)addTextToFlurryArrayForFlurryAndSavedLists:(NSString*)text{
if ([_flurryArray count]==0 &&[text length]>0) {
[_flurryArray addObject:text];
}
for (int i=0;i<[_flurryArray count];i++) {
NSString *textInArray=[_flurryArray objectAtIndex:i];
if (![textInArray isEqualToString:text]) {
[_flurryArray addObject:text];
}
}
NSLog(#"Total number of saved items = %i",[_flurryArray count]);
}
// Dispose of any resources that can be recreated.
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
The problem is you are only changing the texts in the cells, when those conditions are met. For example, when your cellIndexPathSameAsSelected is NO, you leave the cell unmodified. So you should add an else and do some settings there too.
EDIT:
if (cellIndexPathSameAsSelected && _textFromUserDefaults!=nil) {
if (![cell.textLabel.text isEqualToString:_textFromUserDefaults]) {
cell.textLabel.text=_textFromUserDefaults;
[self performTextSearch:_textFromUserDefaults];
}
} else {
cell.textLabel.text = [NSString string];
}
After your [tableView dequeueReusableCellWithIdentifier:kCellID]; call, you have to check if your cell can actually be reusable or not with the followings statements :
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:...];
}
You should be doing something like this
static NSString *kCellID = #"Cell";
// Acquire the cell if possible.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
if (cell == nil) // Not possible to re-use cell, so create a new cell
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
}