[NSCFArray length]: unrecognized selector sent to instance - ios

I'm trying to fill a table view with some data from an array . The array is populated but when i run the app i get this error : reason: '-[__NSCFArray length]: unrecognized selector sent to instance
I searched for similar questions , but no one was the right for me. I don't use the lenght function and my app is crashing on : cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row];
quizViewController.m
- (void)passDataForward
{
ScoreViewController *secondViewController = [[UIStoryboard storyboardWithName:#"Storyboard" bundle:[NSBundle mainBundle]]instantiateViewControllerWithIdentifier:#"score"];
secondViewController.data =self.scoreLabel.text;
secondViewController.delegate = self;
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[highScores insertObject:self.scoreLabel.text atIndex:highScores.count];
NSData *currentDate =[NSDate date];
NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:#"dd.MM.YYYY HH:mm:ss"];
NSString *dateString =[dateFormatter stringFromDate:currentDate];
[data insertObject:dateString atIndex:data.count];
NSMutableArray *scorearray = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:#"high_scoresarray"]];
NSMutableArray *dataArray = [[NSMutableArray alloc] initWithArray:[[NSUserDefaults standardUserDefaults] arrayForKey:#"data_score"]];
[scorearray addObject:highScores];
[dataArray addObject:data];
[[NSUserDefaults standardUserDefaults] setObject:scorearray forKey:#"high_scoresarray"];
[[NSUserDefaults standardUserDefaults] setObject:dataArray forKey:#"data_score"];
secondViewController.test=[NSMutableArray arrayWithArray: scorearray];
secondViewController.currentDate=[NSMutableArray arrayWithArray: dataArray];
[self presentViewController:secondViewController animated:YES completion:^(void)
{
}];
}
ScoreViewController.m
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text = [self.currentDate objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[self.test objectAtIndex:indexPath.row];
return cell;
}

The error means that this line:
[self.currentDate objectAtIndex:indexPath.row]
returns an Array instead of an NSString. Which means that
self.currentDate
contains NSArray objects and not NSString objects.

Aris is right.
self.currentDate returns an NSArray. And that is caused by:
[scorearray addObject:highScores];
[dataArray addObject:data];
Where you are adding one array as the only item to the array scorearray and dataArray respectively. You do not add a bunch of strings, which I assume are stored within highScores and data.
Replace it with
[scorearray addObjectsFromArray:highScores];
[dataArray addObjectsFromArray:data];
That should add the contents of highScores and data to scorearray and dataarray.

Related

Convert NSDictionary to NSArray

I'm trying to convert my NSDictionary (storageData) to an NSArray, as I need to pass the data (title) contained in the dictionary through a segue. I've implemented the below (see last method, the tableview is simply to provide some context), but a crash occurs with the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]:
unrecognized selector sent to instance
Any idea how to fix?
Viewcontrolller.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *DoctorsTableIdentifier = #"StorageItemTableViewCell";
StorageItemTableViewCell *cell = (StorageItemTableViewCell *)[tableView dequeueReusableCellWithIdentifier:DoctorsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"StorageItemTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
NSDictionary *tmp = [self.storageData objectForKey:[NSString stringWithFormat:#"%d",(long)indexPath.row]];
[[cell itemName] setText:(NSString *)[tmp objectForKey:#"title"]];
NSString *title = [tmp objectForKey:#"title"];
[[cell itemName] setText:title];
NSDictionary *node = [self.descripData objectAtIndex:indexPath.row];
[[cell itemDescrip] setText:[node objectForKey:#"body"]];
NSString *secondLink = [[self.descripData objectAtIndex:indexPath.row] objectForKey:#"photo"];
[cell.itemPhoto sd_setImageWithURL:[NSURL URLWithString:secondLink]];
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSArray *values = [self.storageData allKeys];
ItemDetailViewController *detailViewController = [[ItemDetailViewController alloc]
initWithNibName:#"ItemDetailViewController" bundle:nil];
detailViewController.title = [[values objectAtIndex:indexPath.row] objectForKey:#"title"];
detailViewController.itemDetail = [self.descripData objectAtIndex:indexPath.row];
detailViewController.secondLink = self.descripData[indexPath.row][#"photo"];
[self.navigationController pushViewController:detailViewController animated:YES];
}
The error states that you are calling objectForKey in an object of type NSString, which doesn't have that method declared.
So put a breakpoint in the beginning of the method, step over each line one by one until crashes and then check what is the variable that you are thinking is a Dictionary when it is a String.
I believe if you would extract allValues instead of allKeys then you could only:
[values objectAtIndex:indexPath.row]
Since you are using a index as indexPath.row. Let me know if this helps.

TableView not reloading when data is inserted into source from different source

I have a ChatViewController where I send and receive messages and store the messages as a NSMutableDictionary in an NSArray.
NSMutableArray *messages; //in header file
- (void)addMessage:(NSString *)receivedMessage :(NSString *) sender
{
[self reloadDataInTableView:receivedMessage :sender];
}
- (void)reloadDataInTableView:(NSString *)message :(NSString*)sender
{
NSLog(#"Text: %# Sender: %#", message, sender);
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:message forKey:#"msg"];
[m setObject:sender forKey:#"sender"];
[messages addObject:m];
[self.tView reloadData];
NSLog(#"Number of rows: %d", [messages count]);
}
When I am calling 'addMessage' from AppDelegate, both the strings are passed but it cannot add it to the 'messages' because the 'Number of rows' always is zero. But when I am storing it from that class itself then the messages are getting stored and row count increases.
As a result, it only shows the messages from the ChatViewController but not the messages sent from the AppDelegate. I hope I was able to explain the problem properly.
Here is the cellForRowAtIndexPath function:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableDictionary *s = (NSMutableDictionary *) [messages objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
//cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [s objectForKey:#"msg"];
cell.detailTextLabel.text = [s objectForKey:#"sender"];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.userInteractionEnabled = NO;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [messages count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
Yes, I have initialized the messages array in viewDidLoad. But the problem is when I am trying to insert into the messages array from the AppDelegate the count is not increasing. In fact, it always shows zero. But when I insert from the ViewController itself, it maintains the count. Here is the AppDelegate code:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
if ([message isChatMessageWithBody])
{
XMPPUserCoreDataStorageObject *user = [xmppRosterStorage userForJID:[message from]
xmppStream:xmppStream
managedObjectContext:[self managedObjectContext_roster]];
NSString *messageBody = [[message elementForName:#"body"] stringValue];
NSString *displayName = [user jidStr];
if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive)
{
ChatViewController *cvc = [[ChatViewController alloc] init];
[cvc reloadDataInTableView:messageBody :displayName];
}
else
{
// We are not active, so use a local notification instead
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertAction = #"Ok";
localNotification.alertBody = [NSString stringWithFormat:#"From: %#\n\n%#",displayName,messageBody];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
}
}
When you do
ChatViewController *cvc = [[ChatViewController alloc] init];
[cvc reloadDataInTableView:messageBody :displayName];
in your app delegate, you are instantiating a new ChatViewController. Even if the messages array was initialised in the init method (which it isn't, as you said it is initialised in the viewDidLoad method), this new instance of the ChatViewController is discarded at the end of your xmppStream:didReceiveMessage: method and is definitely not the same that is showing on screen.
You need to keep a reference to the proper instance of ChatViewController in your app delegate and use that instead of instantiating a new one...
If you want some more specific advice on how to approach this problem, you'll need to give us more detail about your whole project's architecture (using storyboard? is there a navigation controller? tab controller? how does the chatviewcontroller relate to other view controllers? etc. etc.).
You need
messages = [[NSMutableArray alloc] init];
in viewdidload
Try this:
- (void)reloadDataInTableView:(NSString *)message :(NSString*)sender
{
NSLog(#"Text: %# Sender: %#", message, sender);
NSMutableDictionary *m = [[NSMutableDictionary alloc] init];
[m setObject:message forKey:#"msg"];
[m setObject:sender forKey:#"sender"];
if (!messages)
{
messages = [[NSMutableArray alloc] init];
}
[messages addObject:m];
[self.tView reloadData];
NSLog(#"Number of rows: %d", [messages count]);
}

The two nsmutablearray value is getting swap with another in ios

I am inserting NSMutableArray(self.tablePdfListArray) in tableview textlabel and NSMutableArray(self.dateListArray) in detailtextlabel at same index. It got added correctly at first place but when I am opening the TableView again the detailTextlabel becoming textlabel and textlabel is becoming detailTextlabel.
I have NSLog both the NSMutabelArray and come to know that both array value are getting swap. How to retain its original values? Thanks in advance for any suggestion.
Edited With tableView code
- (void)viewDidLoad
{
if([[NSUserDefaults standardUserDefaults] objectForKey:#"children"] != nil )
{
self.tablePdfListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"children"]];
}
if ([[NSUserDefaults standardUserDefaults] objectForKey:#"dates"] != nil)
{
self.dateListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"dates"]];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
self.myPDFName = [NSString stringWithFormat:#"%#", [alertView textFieldAtIndex:0].text];
firstDayInYear = [NSDate date];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *currentTime = [dateFormatter stringFromDate:firstDayInYear];
NSLog(#"User's current time in their preference format:%#",currentTime);
if(!self. tablePdfListArray)
{
self.tablePdfListArray = [[NSMutableArray alloc]init];
}
if(!self.dateListArray)
{
self.dateListArray = [[NSMutableArray alloc]init];
}
[self.dateListArray insertObject:currentTime atIndex:0];
NSLog(#"mhy date dateListArray %#",dateListArray);
//the below if condition will not allow repeatative string array in tableList and textfield lenth.
if ([[alertView textFieldAtIndex:0].text length] != 0 && ![self.tablePdfListArray containsObject:self.myPDFName])
{
[self.tablePdfListArray insertObject:[NSString stringWithFormat:#"%#", [alertView textFieldAtIndex:0].text] atIndex:0];
NSLog(#"mhy date tablePdfListArray %#",tablePdfListArray);
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.pdfListnameTable insertRowsAtIndexPaths:#[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.dateListArray forKey:[NSString stringWithFormat:#"children"]];
[defaults setObject:self.tablePdfListArray forKey:[NSString stringWithFormat:#"dates"]];
[defaults synchronize];
}
}}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if( tableView == pdfListnameTable)
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone; //cell bg
//self.myChklist.backgroundColor = [UIColor clearColor];
}
NSString *tablePdfname = [self.tablePdfListArray objectAtIndex:indexPath.row];
cell.textLabel.text = tablePdfname;
NSString *tablePdfdate = [self.dateListArray objectAtIndex:indexPath.row];
//[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
cell.detailTextLabel.text = tablePdfdate;
return cell;
}
}
Why are you checking tableView == pdfListnameTable ?
That should be tableView isEqual:self. pdfListnameTable. Not sure that is relevant here, but if you have more than one tableView - i'd guess that you aren't switching to it as there seems to be a lack of an else statement for that.
Well, I'm not sure but I did a little refactoring of your code. You have some places where it looks like you're trying to access a property, but then you're also trying to access it as an instance value.
So, here is what I did. It may not be correct. but it should be close (or at least will help you figure this out)
#interface someTableViewController()
#property(nonatomic, strong) NSMutableArray *tablePdfListArray;
#property(nonatomic, strong) NSMutableArray *dateListArray;
#property(nonatomic, copy) NSString *myPDFName;
#property(nonatomic, strong) NSDate *firstDayInYear;
#property(nonatomic, strong) NSDateFormatter *dateFormatter;
#property(nonatomic, weak) IBOutlet UITableView *pdfListnameTable;
#end
#implementation someTableViewController
-(void)viewDidLoad {
self.tablePdfListArray = [NSMutableArray new];
self.dateListArray = [NSMutableArray new];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults objectForKey:#"children"] != nil ) {
self.tablePdfListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"children"]];
}
if([userDefaults objectForKey:#"dates"] != nil) {
self.dateListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:#"dates"]];
}
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone; //cell bg
NSInteger currentRow = indexPath.row;
NSString *tablePdfname = [self.tablePdfListArray objectAtIndex:currentRow];
cell.textLabel.text = tablePdfname;
NSString *tablePdfdate = [self.dateListArray objectAtIndex:currentRow];
cell.detailTextLabel.text = tablePdfdate;
UIButton *someButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[someButton setTitle:#"CLICK" forState:UIControlStateNormal];
[someButton addTarget:self action:#selector(testButtonClickIndexPath:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:someButton];
return cell;
}
-(void)testButtonClickIndexPath:(id)sender {
CGPoint touchPoint = [sender convertPoint:CGPointZero toView:self.pdfListnameTable];
NSIndexPath *indexPath = [self.pdfListnameTable indexPathForRowAtPoint:touchPoint];
if(indexPath != nil) {
// show alert message, call it, or whatever. just using a silly one for now..
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"RAR"
message:#"Mamma Say..my..my mamma say"
delegate:self
cancelButtonTitle:#"Medulla Oblongata"
otherButtonTitles:#[ #"h2o", #"Gatorade"]];
[alert show];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0) {
self.myPDFName = [NSString stringWithFormat:#"%#", [alertView textFieldAtIndex:0].text];
self.firstDayInYear = [NSDate date];
self.dateFormatter = [[NSDateFormatter alloc] init];
[self.dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[self.dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *currentTime = [self.dateFormatter stringFromDate:self.firstDayInYear];
NSLog(#"User's current time in their preference format:%#",currentTime);
[self.dateListArray insertObject:currentTime atIndex:0];
NSLog(#"mhy date dateListArray %#",self.dateListArray);
//the below if condition will not allow repeatative string array in tableList and textfield lenth.
if([[alertView textFieldAtIndex:0].text length] != 0 && ![self.tablePdfListArray containsObject:self.myPDFName]) {
[self.tablePdfListArray insertObject:[NSString stringWithFormat:#"%#", [alertView textFieldAtIndex:0].text] atIndex:0];
NSLog(#"mhy date tablePdfListArray %#",self.tablePdfListArray);
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.pdfListnameTable insertRowsAtIndexPaths:#[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.dateListArray forKey:[NSString stringWithFormat:#"dates"]];
[defaults setObject:self.tablePdfListArray forKey:[NSString stringWithFormat:#"children"]];
[defaults synchronize];
}
}
}
#end

Does assigning an autorelease object to a retained property increase its retain count?

I would have thought 'self.data=' would retain the autorelease NSMutableArray objects and the NSMutableDictionary objects it contains, but eventually I get EXC_BAD_ACCESS when the table's cellForRowAtIndexPath method tries to access the NSDictionaries in self.data.
#property (strong, nonatomic) NSMutableArray *data;
- (void) updateReceivedData:(NSData *) jsonData
{
NSMutableArray *fetchedData = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
self.data = [self convertDates:fetchedData withFormat:kMySQLDateTimeFormat];
[self.tableView reloadData];
}
}
- (NSMutableArray*) convertDates:(NSMutableArray *) array withFormat:(NSString *) format
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];
NSMutableArray *newArray = [NSMutableArray arrayWithArray:array];
for (NSMutableDictionary *dict in newArray)
{
for (id key in dict.allKeys)
{
if ([[dict objectForKey:key] isKindOfClass:[NSString class]])
{
NSString *value = [dict objectForKey:key];
NSDate *date = [dateFormatter dateFromString:value];
if (date) [dict setObject:date forKey:key];
}
}
}
[dateFormatter release];
return newArray;
}
BAD_ACCESS HERE thrown here between the NSLogs.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog (#"Cell was nil");
cell = [[[CustomCell alloc] init] autorelease];
}
NSDictionary *dict = [[NSDictionary alloc] init];
if (_isFiltered){
dict = [self.filteredData objectAtIndex:indexPath.row];
} else {
dict = [self.data objectAtIndex:indexPath.row];
}
NSLog (#"Filling Label 1");
cell.IDLabel.text = [[dict objectForKey:#"Id"] stringValue];
NSLog (#"Filling Label 2");
cell.firstNameLabel.text = [dict objectForKey:#"firstName"];
[dict release];
return cell;
}
Turn on zombies and see if it catches the problem (EXC_BAD_ACCESS does not necessarily mean an over-released object, but it might).
What happens to the absolute value of the retain count of an object is irrelevant.
However, a strong property implies that the object is retained, yes, if you assign through the setter (i.e. self.data = ... and not _data = ...).
Why are you releasing the dict in cellForRowAtIndexPath: . Eventhough you allocate dict, you are assigning another pointer which is an object from filteredData or data. Just remove the [data release] and while declaring data assign it as nil
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSLog (#"Cell was nil");
cell = [[[CustomCell alloc] init] autorelease];
}
// **As you will be assigning the object from filteredData/data, don't allocate here**
NSDictionary *dict = nil;
if (_isFiltered){
dict = [self.filteredData objectAtIndex:indexPath.row];
} else {
dict = [self.data objectAtIndex:indexPath.row];
}
NSLog (#"Filling Label 1");
cell.IDLabel.text = [[dict objectForKey:#"Id"] stringValue];
NSLog (#"Filling Label 2");
cell.firstNameLabel.text = [dict objectForKey:#"firstName"];
// **Release not required as you didn't allocate**
//[dict release];
return cell;
}

-[__NSCFString objectAtIndex:] cellForRowAtIndexPath: crashes when trying to access arrays objectAtIndex:indexPath.row

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xa84a800'
I am loading in data to a UITableView, from a custom UITableViewCell (own class and nib). It works great, Until i try to access the objectAtIndex:indexPath.row for some arrays.
I'll post my code first, It will probably be easier for you to understand what I mean then.
-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden=YES;
if (managedObjectContext==nil) {
MFAppDelegate *appDelegate = (MFAppDelegate *)[UIApplication sharedApplication].delegate;
managedObjectContext = appDelegate.managedObjectContext;
}
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Last" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
// Handle the error.
}
// Set self's events array to the mutable array, then clean up.
[self setFinal:mutableFetchResults];
lastdisarr=[mutableFetchResults valueForKey:#"lastdis"];
lastcalarr=[mutableFetchResults valueForKey:#"lastcal"];
lasttimearr=[mutableFetchResults valueForKey:#"lasttime"];
date=[mutableFetchResults valueForKey:#"lastspeed"];
lasticonarr=[mutableFetchResults valueForKey:#"iconwe"];
NSLog(#"LAst DISTANCE %#",lasticonarr);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell";
Cell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle]loadNibNamed:#"Cell" owner:self options:nil];
cell=self.custom;
}
// Set up the cell...
cell.distance.text=[lastdisarr objectAtIndex:indexPath.row];
cell.timelab.text=[lasttimearr objectAtIndex:indexPath.row];
cell.callab.text=[lastcalarr objectAtIndex:indexPath.row];
cell.date.text=[date objectAtIndex:indexPath.row];
//cell.wether.image=[lasticonarr objectAtIndex:indexPath.row];
NSMutableArray *ar=[lasticonarr objectAtIndex:indexPath.row];
NSLog(#"%#",ar);
//problem is here
//i want to show image in custom cell & get path from core data....path is getting but image not show on cell
NSURL *url1 = [NSURL URLWithString:[ar objectAtIndex:indexPath.row]];
NSLog(#"%#",url1);
NSData *data = [NSData dataWithContentsOfFile:[ar description]];
NSLog(#"%#",data);
return cell;
}
there are two option:
1: you haven't retained your value;
lastdisarr = [[mutableFetchResults valueForKey:#"lastdis"] retain];
lastcalarr = [[mutableFetchResults valueForKey:#"lastcal"] retain];
lasttimearr = [[mutableFetchResults valueForKey:#"lasttime"] retain];
2: [mutableFetchResults valueForKey:#"lastdis"] is an NSString, and not an NSArray, as expected.

Resources