last day (14 days later) » 

3:14 PM
0
A: UITableview - set different custom cells depending on current day

rdelmarYou just need to dequeue the cell you want depending on the value of self.weeksRotation[indexPath.row]. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if ([self.weeksRotation[indexPath.row] isEqualToString:@"Saturday"] || [self.weeks...

 
okay yes but I have a bunch of ways that the cells need to be arranged, about 20, and I feel like there is a better way to do that? See this question for details.
 
@daveneedleman, I don't see anything in your edit that would require 20 arrangements. If there are really that many, then you need to more fully describe your requirements. How is the user going to choose the dining hall? Do you want one dining hall per table view, or do you want to show all the dining halls for a school in one table view.
 
its one per tableview, and they have already chosen that and I send that data to the tableview as a string wight he dining hall they have chosen.
 
@daveneedleman, I edited my answer to give you one way that might work for you.
 
okay but then where is albany1/ albany2 used in cellForRowAtIndexPath
also this line NSInteger buttonNumber = [self.weeksRotation[indexPath.row][@"meals"] count]; Throws this exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString objectForKeyedSubscript:]
 
3:14 PM
@daveneedleman, As I said, you use whatever info you send from the initial controller to pick which of the arrays you use. Then you do the shuffling to create the weeksRotation array, and that's what gets passed to the data source methods. The way the arrays are set up, it should work with any of the arrays, since they contain the information within them to determine which cell to dequeue. As for that error, have you created the array like I showed, and then used that to create the weeksRotationArray? What does a log of [self.weeksRotation[indexPath.row] show?
 
what do you mean by weekRotation array, I was confusing that daysOfTheWeekArray.
I can't see where weeks rotation array is declared
 
It's in the code you posted.
At the end of viewDidLoad
 
oh this line self.weeksRotation = temp;
 
Yes, you need to change the way that's created so you can pass whichever of the arrays you need to use for the table.
 
how should I declare it, because the way I do it now isn't working?
which is in my .h file
 
3:20 PM
How are you declaring it?
 
in .h @property (strong,nonatomic) NSArray *weeksRotation;
in viewDidLoad I set it to self.weeksRotation = temp;
 
That should work. What do you mean, it's not working?
 
when this is called NSInteger buttonNumber = [self.weeksRotation[indexPath.row][@"meals"] count]; , in cellFOrRow, it thaws error
 
What does a log of [self.weeksRotation[indexPath.row] show? Put that log in as the first line in cellForRowAtIndexPath
 
When I NSLog (@"%d", weeksRotation[indexPath.row])
I get 92920800
and then a bunch of other numbers near 92920800
 
3:23 PM
self.weeksRotation[indexPath.row] should return a dictionary, not a number, so you need to log that with %@, not %d
 
I get Friday \n Saturday \n Sunday ...
 
Can you copy and paste the actual output of that log
 
2014-10-17 11:24:18.726 U Eat[59654:1825109] Friday
2014-10-17 11:24:18.728 U Eat[59654:1825109] Saturday
2014-10-17 11:24:18.729 U Eat[59654:1825109] Sunday
2014-10-17 11:24:18.729 U Eat[59654:1825109] Monday
2014-10-17 11:24:18.730 U Eat[59654:1825109] Tuesday
2014-10-17 11:24:18.730 U Eat[59654:1825109] Wednesday
2014-10-17 11:24:18.731 U Eat[59654:1825109] Thursday
 
It looks like you haven't used the array albany1 like I showed in my edit to create the weeksRotation array.
*create not edit
sorry ignore that
 
3:29 PM
I would move the code that creates the weeksRotation array out of viewDidLoad into its own method. Something like this,
- (void)viewDidLoad {
[super viewDidLoad];

NSArray *albany1 = @[@{@"day":@"Sunday", @"meals":@[@"Lunch", @"dinner"]}, @{@"day":@"Monday", @"meals":@[@"Breakfast",@"Lunch", @"dinner"]},@{@"day":@"Tuesday", @"meals":@[@"Breakfast",@"Lunch", @"dinner"]},@{@"day":@"WednesDay", @"meals":@[@"Breakfast",@"Lunch", @"dinner"]},@{@"day":@"Thursday", @"meals":@[@"Breakfast",@"Lunch", @"dinner"]},@{@"day":@"Friday", @"meals":@[@"Breakfast",@"Lunch", @"dinner"]},@{@"day":@"Saturday", @"meals":@[@"Lunch", @"dinner"]}];
But you would have your other arrays in viewDidLoad as well, and use your logic to decide which array you pass to the shuffleArray:forDayNumber: method
 
okay so now I have this error Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to instance 0x7f80c591dfa0'
theres a warning in viewDidLoad that Local Declataion of albany1 hides instance varaible
 
If you made an instance variable for albany1, then you should just have albany1 = @[... without the NSArray in front.
There's not really any need to have an instance variable though, since that array won't be used outside of viewDidLoad.
 
okay thats good now but I still am getting this error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI length]: unrecognized selector sent to
 
Change the log to NSLog(@"%@",self.weeksRotation) and show me the results from that
 
2014-10-17 11:40:11.784 U Eat[60268:1837999] (
{
day = Friday;
meals = (
Breakfast,
Lunch,
dinner
);
},
{
day = Saturday;
meals = (
Lunch,
dinner
);
},
{
day = Sunday;
meals = (
Lunch,
dinner
);
},
{
day = Monday;
meals = (
Breakfast,
Lunch,
dinner
);
},
{
day = Tuesday;
meals = (
Breakfast,
Lunch,
dinner
);
},
{
day = WednesDay;
meals = (
Breakfast,
Lunch,
dinner
);
},
{
day = Thursday;
meals = (
Breakfast,
Lunch,
dinner
);
}
)
 
3:41 PM
OK, that looks fine. So is it the log NSLog(@"%@",self.weeksRotation[indexPath.row]) that gives you the error?
 
no that logs fine
2014-10-17 11:42:23.255 U Eat[60358:1839899] {
day = Friday;
meals = (
Breakfast,
Lunch,
dinner
);
}
 
So what line is causing the error?
 
I think it is -(void)shuffleArray:(NSArray *) arr forDayNUmber:(NSInteger) dayNumber {
NSMutableArray *temp = [[arr subarrayWithRange:NSMakeRange(dayNumber, 7- dayNumber)] mutableCopy];
[temp addObjectsFromArray:[arr subarrayWithRange:NSMakeRange(0, 7 - temp.count)]];
self.weeksRotation = temp;

}
1 sec
Yes when I removed the function call it ran
 
Do you know how to add an exception breakpoint?
 
yes give me one sec
okay fixed it there was an extra cell calling the dictionary which made it break
thanks so much for your help
 
3:48 PM
You're welcome.
Any more questions?
 
I got one off topic quesiont I say in your bio that your self taught, I started coding about 5 months ago, and am self taught/ stack overflow taught, just wondering where you learned, if you know any good free sources?
 
Mostly I learned by reading Apple's documentation, and making lots of little test apps. I also went through the Stanford online course CS193P.
 
Cool. You have any apps on store?
 
Nope. I mostly program for fun, and do consulting for other people and companies.
 

last day (14 days later) »