I am still rather new at this, seeing as this is my first project and all. But I have complete faith in the stack overflow community as you all have helped me before.
I have a rather interesting conundrum for you all. I call the standard:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
in my tableview to have it push a view controller, and update the value of string (method below)(The change in string is NSLogged by a different method):
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
appDelegate.baseURL = nil;
musicInteractionController = [[xSheetMusicViewController alloc]init];
if (indexPath.row == 0 && indexPath.section == 0) {
appDelegate.baseURL = @"mussette.pdf";
[self.navigationController pushViewController:musicInteractionController animated:YES];
}
else if (indexPath.row == 1 && indexPath.section == 0) {
appDelegate.baseURL = @"Importing PDF's.pdf";
[self.navigationController pushViewController:musicInteractionController animated:YES];
}
else if (indexPath.row == 2 && indexPath.section == 0) {
appDelegate.baseURL = @"Example.pdf";
[self.navigationController pushViewController:musicInteractionController animated:YES];
}
else if (indexPath.section == 1) {
appDelegate.baseURL = [[ivContentsList objectAtIndex:indexPath.row]lastPathComponent];
[self.navigationController pushViewController:musicInteractionController animated:YES];
}
[musicInteractionController release]; musicInteractionController = nil;
appDelegate.baseURL = nil;
}
My code has no errors, warnings, or memory leaks in it. And the change in string it read by a new view controller that updates the view to display the current PDF. It works correctly, but keeps displaying the same PDF over and over again, despite a change in the NSLog value. If it helps, I am using the iOS simulator, and not a real device.
Here is a sample NSLog after pushing the first cell, then the second (ignore the nil view controller log, I think it's a bug. Also, the down Log is from a private method in the second view, so it can also be ignored. And a bonus to those who can resolve the CGContextClipToRect: invalid context 0x0 warning):
2011-09-15 16:24:23.731 SheetMuse[43068:b603] value - (null)
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGContextClipToRect: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGContextGetClipBoundingBox: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGCo开发者_高级运维ntextConcatCTM: invalid context 0x0
Sep 15 16:24:27-MacBook SheetMuse[43068] <Error>: CGBitmapContextCreateImage: invalid context 0x0
2011-09-15 16:24:27.050 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c5e220>.
2011-09-15 16:24:27.069 SheetMuse[43068:b603] value - mussette.pdf
2011-09-15 16:24:27.072 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4e74620>.
2011-09-15 16:24:27.097 SheetMuse[43068:b603] value - mussette.pdf
2011-09-15 16:24:33.944 SheetMuse[43068:b603] Down
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextClipToRect: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextGetClipBoundingBox: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGContextConcatCTM: invalid context 0x0
Sep 15 16:24:36 MacBook-SheetMuse[43068] <Error>: CGBitmapContextCreateImage: invalid context 0x0
2011-09-15 16:24:36.587 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c54bf0>.
2011-09-15 16:24:36.588 SheetMuse[43068:b603] value - Importing PDF's.pdf
2011-09-15 16:24:36.590 SheetMuse[43068:b603] Application tried to push a nil view controller on target <UINavigationController: 0x4c50790>.
2011-09-15 16:24:36.591 SheetMuse[43068:b603] value - Importing PDF's.pdf
Thanks in advance.
Here is a sample NSLog after pushing the first cell, then the second (ignore the nil view controller log, I think it's a bug. Also, the down Log is from a private method in the second view, so it can also be ignored. And a bonus to those who can resolve the CGContextClipToRect: invalid context 0x0 warning)
I know it is tempting to think that these aren't related, but it is important to remember that bugs are like snowballs - they accumulate more snow when they start rolling.
musicInteractionController = [[xSheetMusicViewController alloc]init];
The log seems to be indicating that your musicInteractionController is nil. I haven't seen your init code for xSheetMusicViewController (by the way, I recommend using Apple's suggestions for class and variable naming: classes start with upper case and variables start with lower case) I cannot say why, but a subclass of UIViewController should probably use - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle to init.
My guess is that if you solve the nil view controller you will solve the other bugs.
Update
From Apple's docs:
This is the designated initializer for this class.
The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad method and perform your tasks there.
If you specify nil for the nibName parameter, you must either override the loadView method and create your views there or you must provide a nib file in your bundle whose name (without the .nib extension) matches the name of your view controller class. (In this latter case, the class name becomes the name stored in the nibName property.) If you do none of these, the view controller will be unable to load its view.
So, everything will need to be setup in the loadView method for the class. Can you show us how you implemented that method?
Try calling the index differently, because I've had this problem before and with some debugging I found that the index changes as you scroll through a table based on the active view rather than the actual table.
Try calling the index with this:
int someIndexVar = [indexPath indexAtPosition: [indexPath length] - 1];
and try
if (someIndexVar == 0 && someIndexVar.section == 0) {
EDIT: add
return cell;
after every item in each if each statement i.e:
if (this){
code
return cell;
} else if (this){
code
return cell;
} else {
code
return cell;
}
Most people say the cell doesn't need to be returned every time but it has to since its an if statement and it only returns the cell if chosen, that fixed the problem for me
精彩评论