UITableViewCell - unrecognized selector sent to instance - ios

I'm trying to implement a right swipe to the left but is giving this error :
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '- [UITableViewCell
setDelegate]: unrecognized selector sent to instance 0x7fbadb85d710'
this error of the lines:
cell.delegate = self;
cell.allowsMultipleSwipe = allowMultipleSwipe;
cell.rightSwipeSettings.transition = data.transition;
cell.rightExpansion.buttonIndex = data.rightExpandableIndex;
cell.rightExpansion.fillOnTrigger = YES;
cell.rightButtons = [self createRightButtons:data.rightButtonsCount];
my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MGSwipeTableCell *cell ;
static NSString * reuseIdentifier = #"listAlbuns";
cell = [self.tblAlbum dequeueReusableCellWithIdentifier:reuseIdentifier];
if (!cell) {
cell = [[MGSwipeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
}
NSString *sectionTitle = [albumSectionTitles objectAtIndex:indexPath.section];
NSMutableDictionary *sectionAlbuns = [albuns objectForKey:sectionTitle];
NSString *title = [sectionAlbuns objectForKey: [NSString stringWithFormat:#"%i", indexPath.row]];
NSMutableDictionary *album = [baseController getCurrentItemByTitle: albunsBD :title];
TestData *data = [tests objectAtIndex:indexPath.row];
NSInteger ID = [album objectForKey: #"1"];
cell.textLabel.text = [album objectForKey: #"2"];
cell.detailTextLabel.text = [[albumDAO selectArtistByAlbumID: ID] uppercaseString];
cell.imageView.image = [UIImage imageNamed: #"icones-categorias-album"];
cell.imageView.image = [albumDAO getThumb: ID];
cell.tag = [album objectForKey: #"1"];
cell.delegate = self;
cell.allowsMultipleSwipe = allowMultipleSwipe;
cell.rightSwipeSettings.transition = data.transition;
cell.rightExpansion.buttonIndex = data.rightExpandableIndex;
cell.rightExpansion.fillOnTrigger = YES;
cell.rightButtons = [self createRightButtons:data.rightButtonsCount];
return cell;
}
anyone have any idea what can be?

Since you are trying to use a UITableViewCell subclass, MGSwipeTableViewCell, you must ensure the cell you are getting back from dequeueReusableCellWithIdentifier returns an MGSwipeTableViewCell.
Firstly, you can remove the if (!cell) { ... } block, as dequeueReusableCellWithIdentifier should return a UITableViewCell if you have the identifier set in a .xib or on the storyboard. Having the extra block can make this code harder to debug if the cell doesn't have a reuse identifier on the storyboard or .xib.
Next, in your .xib or storyboard where the cell you are trying to dequeue exists, select the prototype UITableViewCell and look at the box named "Class" under the section "Custom Class". Change this to MGSwipeTableViewCell, as I suspect it is set to UITableViewCell. This should fix the problem. Here is the area in Xcode I am talking about:
You should be able to set cell.delegate and other MGSwipeTableViewCell properties after you dequeue a real MGSwipeTableViewCell.

Related

NSCFConstantString objectAtIndex unrecognized selector sent to instance

I am getting the above mentioned error and do not know why because I implemented the same code in another example. "services" is my NSMutableArray and "service name" is the label on table view with Tag 2. In viewdidload I fill the service array with objects.
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"servicesCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UILabel *servicesName;
UILabel *nrofService;
if(tableView == self.servicetable)
{
servicesName = (UILabel*) [cell viewWithTag:2];
servicesName.text = [[services objectAtIndex:0] objectAtIndex:indexPath.row];
}
return cell;
}
The problem is on the below line:
servicesName.text = [[services objectAtIndex:0] objectAtIndex:indexPath.row];
Check [services objectAtIndex:0] is returning NSString instead of NSArray or NSMutableArray. So you are calling objectAtIndex:indexPath.row on NSString which causes the exception:
NSCFConstantString objectAtIndex unrecognized selector sent to
instance
So set your UILabel text as below:
servicesName.text = [services objectAtIndex:indexPath.row];

UITableView NSMutableArray and NSDictionary

I’ve got this error when populating a tableview from an nsmutablearray.
The arrays are added to the dictionary and the dictionary added to the mutable array, but the app crashes each time the view is loaded with error:
[__NSArrayI isEqualToString:]: unrecognized selector sent to instance
0x8a87e60 2014-05-24 12:23:02.589 jwStudy[77652:907] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSArrayI isEqualToString:]: unrecognized selector sent to
instance 0x8a87e60'
The log output confirms that the arrays and keys are added correctly.
But why does the cell in the cellForRowAtIndexPath: method throw an error?
Here’s the code:
- (void)viewDidLoad
{
[super viewDidLoad];
languageArray = [[NSMutableArray alloc] init];
languages = [[NSArray alloc] initWithObjects:#"Abbey", #"Abkhasisk", #"Abua", nil];
downloadURL = [[NSArray alloc] initWithObjects:#"http://download.jw.org/files/content_assets/bb/502013341_ABB_cnt_1_r480P.mp4",
#"http://download.jw.org/files/content_assets/3c/502013341_ABK_cnt_1_r480P.mp4",
#"http://download.jw.org/files/content_assets/7e/502013341_AU_cnt_1_r720P.mp4", nil];
mutedict = [NSDictionary dictionaryWithObjectsAndKeys:languages, #"FirstKey", downloadURL, #"SecondKey", nil];
[languageArray addObject:mutedict];
NSLog(#"%#",languageArray);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return languageArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// ERROR HERE!!!
cell.textLabel.text = [[languageArray objectAtIndex:indexPath.row] objectForKey:#"FirstKey”];
if ([checkCellLanguage isEqual:indexPath]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
#Farhan and Joy.
Thank you both for prompt reply. I have realized now that I wasn't clear enough in my question. What I wanted was for each selected row in the tableview to register the row's corresponding URL. So I ended up abandoning the arrays and dictionaries ... too confusing. And going with 2 NSArrays instead. This link got me going on the right track and everything works now:
http://sweettutos.com/2012/08/25/loading-urls-from-uitableview/
In your code, two arrays stored in a dictionary , and the dictionary stored in a array.
Like this :
languageArray ----- mutedict ------ languages (FirstKey)
|
|
----------- downloadURL(SecondKey)
cell.textLabel.text is a NSString, but [[languageArray objectAtIndex:indexPath.row] objectForKey:#"FirstKey”]; is NSArray
So your code throw an error.
If your want put a language as cell.textLabel.text
You could modify your code as cell.textLabel.text = [[mutedict objectForKey:#"FirstKey"] objectAtIndex:indexPath.row]
Hope it can help you :)

Use a custom UITableViewCell for many UITableView

I have created a custom UITableViewCell for a UITableView by dragging and dropping the labels and imageView from my Prototype Cell to a Custom Cell which I call QuizInfoCell.
That works fine for the particular TableView that I created the Prototype Cell in, but I can't get QuizInfoCell to work for any other TableView. How can I achieve that?
This is the code that I'm using in the TableView that created the Prototype Cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QuizInfoCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"QuizInfoCell" forIndexPath:indexPath];
if (cell == nil){
cell = [[QuizInfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"QuizInfoCell"];
}
cell.name.text = [title objectAtIndex:indexPath.row];
cell.author.text = [author objectAtIndex:indexPath.row];
cell.time.text = [[ValueHandler alloc] getDateString:[timeStamp objectAtIndex:indexPath.row]];
cell.plays.text = [#"Plays: " stringByAppendingString:[NSString stringWithFormat:#"%#", [plays objectAtIndex:indexPath.row ]]];
cell.ratingUps.text = [NSString stringWithFormat:#"%#", [ratingUps objectAtIndex:indexPath.row]];
cell.ratingDowns.text = [NSString stringWithFormat:#"%#", [ratingDowns objectAtIndex:indexPath.row]];
cell.qid.text = [NSString stringWithFormat:#"%#", [qid objectAtIndex:indexPath.row]];
return cell;
}
I suggest creating your QuizInfoCell as a new XIB file.
Press CMD + N
Select the User Interface submenu.
Create a new View and call it QuizInfoCell
In your new XIB delete the existing View element and instead drag and drop a new Table View Cell.
Recreate your custom UITableViewCell in the same way as you did before by dragging and dropping the labels and imageView
Finally give the new Cell an Identifier called QuizInfoCell, like this:
You can then load your new Custom UITableViewCell with Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
QuizInfoCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"QuizInfoCell" forIndexPath:indexPath];
if (cell == nil){
NSArray *nibContents = [[NSBundle mainBundle] loadNibNamed:#"QuizInfoCell" owner:self options:nil];
cell = [nibContents objectAtIndex:0];
}
cell.name.text = [title objectAtIndex:indexPath.row];
cell.author.text = [author objectAtIndex:indexPath.row];
cell.time.text = [[ValueHandler alloc] getDateString:[timeStamp objectAtIndex:indexPath.row]];
cell.plays.text = [#"Plays: " stringByAppendingString:[NSString stringWithFormat:#"%#", [plays objectAtIndex:indexPath.row ]]];
cell.ratingUps.text = [NSString stringWithFormat:#"%#", [ratingUps objectAtIndex:indexPath.row]];
cell.ratingDowns.text = [NSString stringWithFormat:#"%#", [ratingDowns objectAtIndex:indexPath.row]];
cell.qid.text = [NSString stringWithFormat:#"%#", [qid objectAtIndex:indexPath.row]];
return cell;
}

tableview returns error (datasource must return a cell)

I am trying to update my app to iOS 7 but allot of things just disappeared or don't work anymore :S.
I cant figure this problem out, i dont know why it returns NULL.
*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"Cell";
static NSString *cellIdentifier2 = #"Cell2";
NSDictionary *naamInfo;
if (tableView == self.searchDisplayController.searchResultsTableView) {
naamInfo = [self.filteredNameArray objectAtIndex:indexPath.row];
} else {
naamInfo = [self.nameList objectAtIndex:indexPath.row];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if ([[naamInfo objectForKey:#"gender" ] isEqual: #"man"] ) {
cell = [UITableViewCell configureFlatCellWithColor:[UIColor peterRiverColor] selectedColor:[UIColor cloudsColor] reuseIdentifier:cellIdentifier inTableView:tableView];
}else if ([[naamInfo objectForKey:#"gender" ] isEqual: #"woman"]){
cell = [UITableViewCell configureFlatCellWithColor:[UIColor colorWithRed:1 green:0.396 blue:0.604 alpha:1] selectedColor:[UIColor cloudsColor] reuseIdentifier:cellIdentifier2 inTableView:tableView];
}
NSLog(#"CELL %#",cell);
cell.detailTextLabel.font = [UIFont boldFlatFontOfSize:14];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.cornerRadius = 8.f;
cell.separatorHeight = 1.f;
cell.textLabel.font = [UIFont boldFlatFontOfSize:18];
cell.textLabel.text = [naamInfo objectForKey:#"name"];
cell.detailTextLabel.text = [naamInfo objectForKey:#"country"];
return cell;
}
The log returns a NULL so i understand why i get the exception, what i dont get is how can i fix this problem ?
Try to put:
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
after:
UITableViewCell *cell = [tableView dequeue....

Program received Signal SIGABRT when scrolling up UITableView

When i scroll my UITableView down and then scrolling up, the app crashes with the stack below:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2147483647 beyond bounds [0 .. 48]'
I know it's saying that i am accessing a cell index that exceed the UITableView size, but i am not able to figure out how to fix it. this may be my relevant code:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"CheckedTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
NSDictionary *rowData = [self.tableData objectAtIndex:[self tableIndexFromIndexPath:indexPath]];//this line may be the source of the crash
cell.textLabel.text = [rowData objectForKey:kCellTextKey];
if ([[rowData objectForKey:kCellStateKey] boolValue]) {
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"checked.png"]];
cell.accessoryView = imageView1;
} else {
UIImageView *imageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"unchecked.png"]];
cell.accessoryView = imageView2;
}
return cell;
}
EDIT:
Here is my tableIndexFromIndexPath method implementation
- (NSUInteger)tableIndexFromIndexPath:(NSIndexPath *)indexPath {
// Get list of items at selected section
NSArray *listData = [tableContents objectForKey:[sortedKeys objectAtIndex:indexPath.section]];
// Get name of selected row within the section
NSString *textKey = [listData objectAtIndex:indexPath.row];
// Look up that name in the tableData array
for (int i=0; i < [tableData count]; i++) {
NSDictionary *dict = [tableData objectAtIndex:i];
if ([[dict objectForKey:kCellTextKey] isEqualToString:textKey]) {
return i;
}
}
//In case Name was not found
return NSNotFound;
}
Change
NSDictionary *rowData = [self.tableData objectAtIndex:[self tableIndexFromIndexPath:indexPath]];
to
NSDictionary *rowData = [self.tableData objectAtIndex:indexPath.row];
As several have noted, your tableIndexFromIndexPath: is incorrect. Specifically it's returning NSNotFound, which suggests your using something like indexOfObject: for an object that is not in the array.
At first check that are you getting all value of your NSMutableArray?
If you are getting then check your number of section of tableView is equal to number of NSMutableArray array or not?
If same then there is a reload problem then reload your table view when you are inserting data into the NSMutableArray.
I hope you will find your solution among them.

Resources