Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
In each custom cell, there is text in a uilabel that is loaded from a nsmutablearray. One of the nsmutablearray's holds int's The other nsmutablearray's holds nsdate in an unformatted form
I am trying to sort the cells based upon the highest int or the newest date. I got as far as getting the highest int in the array and getting the newest date but I am not sure how to reorder the cells in the way I explained. If anyone can help maybe make my current code better or help me redorder the rows that would be great. Also in the second if statement, how would I make a loop to loop through the array putting the highest int on top and it will ascend down? I am not asking for code but just some help/tips.
dljefferyPosts: 1,311iPhone Dev SDK Supporter, Registered Users
Table view cells are meant to be transient views. Don't hang onto your cells and try to keep them sorted. Rather, just sort your data, and every time you're asked for a cell for some record, dequeue a reusable cell or create a new one, and then put the relevant data into it.
That is, don't return a certain cell for a certain index. Put certain data into a transient cell for a certain index.
Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
I am taking your advice and I am going to do it your way. I started to do this but there is a crash in my app, something like, something is not 'key-compliant' with nameLabel
This may not have to do with the sorting part but it is very similar to what I will want to do when I want to sort the cells so this will help.
I have a custom UITableViewCell class named TCell and I have 4 IBOutlets connecting UILablels and UIImageViews
I also have NSMutableArrays in my AppDelegate and if there is anything that is wrong in the following code just let me know!
It looks like you dont have something connected properly in IB, specifically your nameLabel. might wanna double check that it is connected.
edit
you are loading the TCell from your nib, and storing it in cell. Thats fine. You shouldnt be allocing a new TCell after that as you are doing. Use cell directlly and set the label values there.
Ok so I did as you said and the same problem. Everything is connected in the TCell class (Cell). This is the Statistics class if that makes a difference. Here is the console error:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Statistics 0x15e910> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key nameLabel.' *** Call stack at first throw:
Here is the cellforrowatindexpath method in Statistics
dljefferyPosts: 1,311iPhone Dev SDK Supporter, Registered Users
Well, it says the problem is with nameLabel, so I'd double and triple check that.
Also, all your code where you're setting the data properties of the cell should be moved outside your if block. Because you want that stuff to happen even if you successfully dequeue a reusable cell.
Recall It!Tag your notes. Tag your photos. Tag your thoughts. Tag your life.
I double checked and even tripled checked that everything is connected, I can even take a picture a post it if necessary. It is still the same problem but a little different now. Here is my new code:
//Put the score, date, name, and profilePicture into the appropriate cell row TestAppDelegate *appDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate]; cell.scoreLabel = [appDelegate.Score objectAtIndex:indexPath.row]; cell.dateLabel = [appDelegate.Dates objectAtIndex:indexPath.row]; cell.nameLabel = [appDelegate.Names objectAtIndex:indexPath.row]; cell.profilePicture.image = [appDelegate.ProfilePictures objectAtIndex:indexPath.row];
return cell;
}
Console Crash Log:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Statistics 0x1ebbe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key profilePicture.'
Can this crash happen if the Score, Dates, Names, or ProfilePictures array's have 0 inside?
<Statistics 0x1ebbe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key profilePicture.
Somewhere, involving a Statistics object instance, you are attempting to do something involving profilePicture. Maybe you removed some code and still have a dangling connection in IB. So, find where you are doing that and remove it. If it is happening in the code you mention there, the problem is likely in the TCell class.
It is certainly not a dangling connection, I checked countless times. If it has to do with the TCell class, would you like me to post the code in it (not to much code)?
I just did and literally copied the code and changed the necessary variables to mine and still the same problem. Are there any specific problems you can think of?
My console still showed this during the crash:
'[<Statistics 0x1c9310> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key scoreLabel.
Ah yes! Ok so I adjusted the things that you tipped me on and now the console error has changed to something else for the crash. It is now:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
Ill recheck the connections but is there a reason for this so I am looking for something specific?
Replies
That is, don't return a certain cell for a certain index. Put certain data into a transient cell for a certain index.
Recall It! for iPad
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI am taking your advice and I am going to do it your way. I started to do this but there is a crash in my app, something like, something is not 'key-compliant' with nameLabel
This may not have to do with the sorting part but it is very similar to what I will want to do when I want to sort the cells so this will help.
I have a custom UITableViewCell class named TCell and I have 4 IBOutlets connecting UILablels and UIImageViews
I also have NSMutableArrays in my AppDelegate and if there is anything that is wrong in the following code just let me know!
Any reason why that would cause a crash like I mentioned above? Can it be because of the arrays being 0?
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomeedit
you are loading the TCell from your nib, and storing it in cell. Thats fine. You shouldnt be allocing a new TCell after that as you are doing. Use cell directlly and set the label values there.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHere is the console error:
Here is the cellforrowatindexpath method in Statistics
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@\"cellForRowAtIndexPath\");
static NSString *CellIdentifier = @\"CellIdentifier\";
TCell *cell = (TCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@\"TCell\" owner:self options:nil];
cell = (TCell *)[array objectAtIndex:0];
//Put the score, date, name, and profilePicture into the appropriate cell row
TestAppDelegate *appDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];
cell.scoreLabel = [appDelegate.Score objectAtIndex:indexPath.row];
cell.dateLabel = [appDelegate.Dates objectAtIndex:indexPath.row];
cell.nameLabel = [appDelegate.Names objectAtIndex:indexPath.row];
cell.profilePicture.image = [appDelegate.ProfilePictures objectAtIndex:indexPath.row];
}
return cell;
}
Any ideas?
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAlso, all your code where you're setting the data properties of the cell should be moved outside your if block. Because you want that stuff to happen even if you successfully dequeue a reusable cell.
Recall It! for iPad
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@\"cellForRowAtIndexPath\");
static NSString *CellIdentifier = @\"CellIdentifier\";
TCell *cell = (TCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@\"TCell\" owner:self options:nil];
cell = (TCell *)[array objectAtIndex:0];
}
//Put the score, date, name, and profilePicture into the appropriate cell row
TestAppDelegate *appDelegate = (TestAppDelegate *)[[UIApplication sharedApplication] delegate];
cell.scoreLabel = [appDelegate.Score objectAtIndex:indexPath.row];
cell.dateLabel = [appDelegate.Dates objectAtIndex:indexPath.row];
cell.nameLabel = [appDelegate.Names objectAtIndex:indexPath.row];
cell.profilePicture.image = [appDelegate.ProfilePictures objectAtIndex:indexPath.row];
return cell;
}
Console Crash Log:
Can this crash happen if the Score, Dates, Names, or ProfilePictures array's have 0 inside?
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeCheck out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSomewhere, involving a Statistics object instance, you are attempting to do something involving profilePicture. Maybe you removed some code and still have a dangling connection in IB. So, find where you are doing that and remove it. If it is happening in the code you mention there, the problem is likely in the TCell class.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeCheck out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeCheck out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeMy console still showed this during the crash:
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAnd the stuff to take away from the tutorial is not copy-pasteable. It is in the xib.
SlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIt is now:
Ill recheck the connections but is there a reason for this so I am looking for something specific?
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomebtw have fun at WWDC :P
Check out my OCR app!
http://itunes.apple.com/app/ocr-pro/id486512712?mt=8
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSlickShopper 2 | BTIConcepts on GitHub | Free NSLog utility | Free Getter Utility | Leave a PayPal donation.
Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | A Model (Object) Is A Beautiful Thing
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome